Documentation
¶
Overview ¶
Package grpc is the grpc transport for plugins/client/orb.
Package grpc provides a gRPC entrypoint for go-orb.
Index ¶
- Constants
- func HTTPStatusToCode(code int) codes.Code
- func Listener(listener net.Listener) server.Option
- func New(acfg any, logger log.Logger, reg registry.Type) (server.Entrypoint, error)
- func Provide(sections []string, configs types.ConfigData, logger log.Logger, ...) (server.Entrypoint, error)
- func WithAddress(addr string) server.Option
- func WithGRPCOptions(opts ...grpc.ServerOption) server.Option
- func WithHandlers(h ...server.RegistrationFunc) server.Option
- func WithHealthService(health bool) server.Option
- func WithInsecure() server.Option
- func WithLogLevel(level string) server.Option
- func WithLogPlugin(plugin string) server.Option
- func WithMiddleware(m string) server.Option
- func WithName(name string) server.Option
- func WithReflection(reflection bool) server.Option
- func WithTLS(config *tls.Config) server.Option
- func WithTimeout(timeout time.Duration) server.Option
- type Config
- type Server
- func (s *Server) Address() string
- func (s *Server) Config() *Config
- func (s *Server) Enabled() bool
- func (s *Server) EntrypointID() string
- func (s *Server) Name() string
- func (s *Server) Register(register server.RegistrationFunc)
- func (s *Server) Start() error
- func (s *Server) Stop(ctx context.Context) error
- func (s *Server) String() string
- func (s *Server) Transport() string
- func (s *Server) Type() string
Constants ¶
const ( // DefaultAddress to listen on. By default a random port will be selected. DefaultAddress = ":0" // DefaultInsecure is set to false to make sure the network traffic is entrypted. DefaultInsecure = false // DefaultgRPCReflection enables reflection by default. DefaultgRPCReflection = true // DefaultHealthService enables the health service by default. DefaultHealthService = true // DefaultTimeout is set to 5s. DefaultTimeout = time.Second * 5 )
const Plugin = "grpc"
Plugin name.
Variables ¶
This section is empty.
Functions ¶
func HTTPStatusToCode ¶
HTTPStatusToCode maps HTTP status codes to gRPC codes.
Falls back to codes.Internal if the code is unrecognized.
func Provide ¶
func Provide( sections []string, configs types.ConfigData, logger log.Logger, reg registry.Type, opts ...server.Option, ) (server.Entrypoint, error)
Provide provides a gRPC server by config.
func WithAddress ¶
WithAddress sets the address to listen on.
If no IP is provided, an interface will be selected automatically. Private interfaces are preferred, if none are found a public interface will be used. To listen on all interfaces explicitly set '0.0.0.0:<port>'.
If no port is provided, a random port will be selected. To listen on a specific interface, but with a random port, you can use '<IP>:0'.
func WithGRPCOptions ¶
func WithGRPCOptions(opts ...grpc.ServerOption) server.Option
WithGRPCOptions with grpc options.
func WithHandlers ¶
func WithHandlers(h ...server.RegistrationFunc) server.Option
WithHandlers adds custom handlers.
func WithHealthService ¶
WithHealthService dictates whether the gRPC health check protocol should be implemented. This is an implementation provided by the grpc package. Defaults to true.
This is useful for healthprobes, such as in Kubernetes (>=1.24).
func WithInsecure ¶
WithInsecure will create the entrypoint without using TLS.
WARNING: don't use this in production, unless you really know what you are doing. this will result in unencrypted traffic. Really, it is even advised against using this in testing environments.
func WithLogLevel ¶
WithLogLevel changes the log level from the inherited logger.
func WithLogPlugin ¶
WithLogPlugin changes the log level from the inherited logger.
func WithMiddleware ¶
WithMiddleware adds a pre-registered middleware.
func WithName ¶
WithName sets the entrypoint name. The default name is in the format of 'grpc-<uuid>'. Setting a custom name allows you to dynamically reference the entrypoint in the file config, and makes it easier to attribute the logs.
func WithReflection ¶
WithReflection dictates whether the server should implementent gRPC reflection. This is used by e.g. the gRPC proxy. Defaults to true.
Types ¶
type Config ¶
type Config struct { server.EntrypointConfig `yaml:",inline"` // Address to listen on. // // If no IP is provided, an interface will be selected automatically. Private // interfaces are preferred, if none are found a public interface will be used. // // If no port is provided, a random port will be selected. To listen on a // specific interface, but with a random port, you can use '<IP>:0'. Address string `json:"address" yaml:"address"` // Insecure will start the gRPC server without TLS. // If set to false, and no TLS certifiate is provided, a self-signed // certificate will be generated. // // WARNING: don't use this in production, unless you really know what you are // doing. this will result in unencrypted traffic. Really, it is even advised // against using this in testing environments. Insecure bool `json:"insecure,omitempty" yaml:"insecure,omitempty"` // TLS config, if none is provided a self-signed certificates will be generated. // // You can load a tls config from yaml/json with the following options: // // “`yaml // rootCAFiles: // - xxx // clientCAFiles: // - xxx // clientAuth: "none" | "request" | "require" | "verify" | "require+verify" // certificates: // - certFile: xxx // keyFile: xxx // “` TLS *mtls.Config `json:"tls,omitempty" yaml:"tls,omitempty"` // GRPCOptions are options provided by the grpc package, and will be directly // passed ot the gRPC server. GRPCOptions []grpc.ServerOption `json:"-" yaml:"-"` // HealthService dictates whether the gRPC health check protocol should be // implemented. This is an implementation provided by the grpc package. // Defaults to true. // // This is useful for healthprobes, such as in Kubernetes (>=1.24). HealthService bool `json:"health" yaml:"health"` // Reflection dictates whether the server should implementent gRPC // reflection. This is used by e.g. the gRPC proxy. Defaults to true. Reflection bool `json:"reflection" yaml:"reflection"` // Timeout adds a timeout to the request context on the request handler. // // The handler still needs to respect the context timeout for this to have // any effect. Timeout time.Duration `json:"timeout" yaml:"timeout"` // Listener is a custom listener. If none provided one will be created with // the address and TLS config. Listener net.Listener `json:"-" yaml:"-"` // Middlewares is a list of middleware to use. Middlewares []server.MiddlewareConfig `json:"middlewares" yaml:"middlewares"` // Handlers is a list of pre-registered handlers. Handlers []string `json:"handlers" yaml:"handlers"` // Logger allows you to dynamically change the log level and plugin for a // specific entrypoint. Logger log.Config `json:"logger" yaml:"logger"` }
Config provides options to the gRPC entrypoint.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is an entrypoint with a gRPC server.
func (*Server) Address ¶
Address returns the address the entypoint listens on, for example: 127.0.0.1:8000 .
func (*Server) EntrypointID ¶
EntrypointID returns the id (uuid) of this entrypoint in the registry.
func (*Server) Register ¶
func (s *Server) Register(register server.RegistrationFunc)
Register executes a registration function on the entrypoint.