The Go language implementation of gRPC TransportCredentials that supports optional TLS connections.
Simple example
optionaltls.New wraps provided TransportCredentials. It uses provided credentials if a client connected with TLS and bypasses if connection is plain-text
import (
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"github.com/noxiouz/go-grpc-optionaltls-creds/optionaltls"
)
// Control in runtime. See docs
var dynamicOptionF = optionaltls.DynamicOption(func() bool {
return true
})
func createServer(credentials credentials.TransportCredentials) *grpc.Server {
serverCredentials = optionaltls.New(credentials) // optionaltls.NewWithDynamicOption(credentials, dynamicOptionF))
s := grpc.NewServer(grpc.Creds(serverCredentials))
return s
}