Skip to content

Instantly share code, notes, and snippets.

@percybolmer
Last active August 6, 2021 11:36
Show Gist options
  • Save percybolmer/25967657fc9ff066272316834c459b02 to your computer and use it in GitHub Desktop.
Save percybolmer/25967657fc9ff066272316834c459b02 to your computer and use it in GitHub Desktop.
A pingcounting grpc Server
// GenerateTLSApi will load TLS certificates and key and create a grpc server with those.
func GenerateTLSApi(pemPath, keyPath string) (*grpc.Server, error) {
cred, err := credentials.NewServerTLSFromFile(pemPath, keyPath)
if err != nil {
return nil, err
}
// Add PingCounter from the interceptors package
pc := interceptors.PingCounter{}
s := grpc.NewServer(
grpc.Creds(cred),
// Here we add the ServerCount interceptor
grpc.UnaryInterceptor(pc.ServerCount),
)
return s, nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment