package
0.0.0-20210210154335-f4159b9fcd5f
Repository: https://github.com/digital-dream-labs/hugh.git
Documentation: pkg.go.dev
# README
Server
To quickly get a grpc server (in this example, with non-system TLS certs) you'd simply do this:
Note: this example uses the grpc example protobufs
func startTestServer() error {
srv, err := server.New(
server.WithCertificate(tls.LocalhostTLSConfig().Certificates[0]),
)
if err != nil {
return err
}
echosrv := grpc.New()
echo.RegisterEchoServer(
srv.Transport(),
echosrv,
)
srv.Start()
<-srv.Notify(server.Ready)
return nil
}
This expects the following environment variables to be in place when calling WithViper() without arguments
Environment Variable | Description | Default |
---|---|---|
DDL_RPC_CLIENT_AUTHENTICATION | Values: [NoClientCert, RequestClientCert, RequireAnyClientCert, VerifyClientCertIfGiven, RequireAndVerifyClientCert] | NoClientCert |
DDL_RPC_TLS_CERTIFICATE | Sets the certificate to use for transport encryption | |
DDL_RPC_KEY | Private key that pairs with tls certificate | |
DDL_RPC_TLS_CA | Load a custom CA pool instead of using the system CA | empty |
DDL_RPC_PORT | Sets the listener port. | 0 |
DDL_RPC_TLS_CA | Sets the certificate authority for client verification | empty |
DDL_RPC_INSECURE | disable TLS verification | false |
A full list of options can be found in options.go
# Functions
New constructs a new Server.
WithCertificate specifies the certificates that will be appended to the tls.Config.
WithCertPool overrides the system cert pool.
WithClientAuth sets the tls ClientAuthType to control auth behavior.
WithHTTPPassthrough starts an additional HTTP passthrough for rest operations.
WithHTTPPassthroughInsecure enables an insecure http passthrough.
WithInsecureSkipVerify makes connections not that safe to use.
WithLogger set the log instance.
WithPort sets the listener port.
WithReflectionService starts a reflection service capable to describing services.
WithStreamServerInterceptors sets the streaming middleware.
WithTLSCert statically sets a TLS certificate.
WithTLSKey statically sets a TLS key.
WithUnaryServerInterceptors sets the unary middleware.
WithViper specifies that the server should construct its options using viper.
# Constants
EnvironmentPrefix sets the prefix to strip from environment variables when resolving keys.
EnvironmentReplace takes a comma separated list of old,new.
Error means the connection is in error.
Init is a new connection.
Ready means the connection is ready.
Starting means the connection is starting.
Stopped means the connection is stopping.
Stopping means the connection is being shut down.