grpctls
GRPCTLS provides helper structs and functions for grpc dialing with TLS options.
Usage
func main() {
uri := "tcp://0.0.0.0:8069"
cfg := grpctls.ServerCfg{
CertFile: "server.crt",
KeyFile: "server.key",
CACert: "ca.crt",
ClientAuth: true,
}
var err error
var creds credentials.TransportCredentials
if cfg.UseTLS() {
creds, err = grpctls.Creds(cfg)
if err != nil {
log.Fatalf("initializing TLS: %v\n", err)
}
}
lis, err := grpctls.Listener(uri)
if err != nil {
log.Fatalf("can't listen server: %v\n", err)
}
grpcs := grpc.NewServer(grpc.Creds(creds))
grpcs.Serve(lis)
}
See examples directory for common use.