Documentation
¶
Overview ¶
Package server provides the go-orb server. It is responsible for managing entrypoints.
Index ¶
- Constants
- Variables
- type Config
- type ConfigOption
- type Entrypoint
- type EntrypointConfig
- type EntrypointConfigType
- type EntrypointNew
- type EntrypointProvider
- type Middleware
- type MiddlewareCallHandler
- type MiddlewareConfig
- type MiddlewareProvider
- type MiddlewareStreamHandler
- type Option
- type RegistrationFunc
- type Server
Constants ¶
const ComponentType = "server"
ComponentType is the server component type name.
const EntrypointType = "server.Entrypoint"
EntrypointType will be returned by each entrypoint on Type().
Variables ¶
var ( ErrUnknownMiddleware = errors.New("unknown middleware") ErrUnknownHandler = errors.New("unknown handler") ErrUnknownEntrypoint = errors.New("unknown entrypoint") )
Errors.
var ( // Plugins is the plugins container for registry. Plugins = container.NewMap[string, EntrypointProvider]() // PluginsNew holds the New function of Entrypoints, it's here // to create entrypoints from given configs. PluginsNew = container.NewMap[string, EntrypointNew]() // Handlers is a container of registration functions that can be used to // dynamically configure entrypoints. // // You need to register your handlers with a registration function to use it. // Example: // Handlers.Register("myHandler", RegisterEchoHandler) Handlers = container.NewMap[string, RegistrationFunc]() )
var DefaultConfigSection = "server" //nolint:gochecknoglobals
DefaultConfigSection is the section key used in config files used to configure the server options.
var ( // Middlewares is the map of Middlewares available for servers. Middlewares = container.NewSafeMap[string, MiddlewareProvider]() //nolint:gochecknoglobals )
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
Middlewares []MiddlewareConfig `json:"middlwares,omitempty" yaml:"middlewares,omitempty"`
Handlers []string `json:"handlers,omitempty" yaml:"handlers,omitempty"`
Entrypoints []EntrypointConfig `json:"entrypoints,omitempty" yaml:"entrypoints,omitempty"`
// contains filtered or unexported fields
}
Config is the global config for servers.
type ConfigOption ¶ added in v0.1.0
type ConfigOption func(*Config)
ConfigOption allows to set options for MyConfig.
func WithEntrypointConfig ¶ added in v0.1.0
func WithEntrypointConfig(config EntrypointConfigType) ConfigOption
WithEntrypointConfig allows you to create an entrypoint functionally.
type Entrypoint ¶
type Entrypoint interface {
types.Component
// Name returns the entrypoints name.
Name() string
// Enabled returns if this entrypoint has been enabled in config.
Enabled() bool
// Register is used to register handlers.
//
// A registration function takes a pointer to the server, which can then
// be used to register handlers in the server specific way.
Register(fun RegistrationFunc)
// Transport returns the client transport that is required to talk to this entrypoint.
Transport() string
// Address returns the address the entrypoint is listening on.
Address() string
// EntrypointID returns the id (uuid) of this entrypoint in the registry.
EntrypointID() string
}
Entrypoint is a server, and represents an entrypoint into the web.
type EntrypointConfig ¶
type EntrypointConfig struct {
Plugin string `json:"plugin" yaml:"plugin"`
Enabled bool `json:"enabled" yaml:"enabled"`
Name string `json:"name,omitempty" yaml:"name,omitempty"`
OptMiddlewares []Middleware `json:"-" yaml:"-"`
OptHandlers []RegistrationFunc `json:"-" yaml:"-"`
}
EntrypointConfig is the base config for all entrypoints.
type EntrypointConfigType ¶ added in v0.1.0
type EntrypointConfigType interface {
// contains filtered or unexported methods
}
EntrypointConfigType is here so we can do magic work on options.
type EntrypointNew ¶ added in v0.1.0
EntrypointNew is the function type to create a new entrypoint.
type EntrypointProvider ¶ added in v0.1.0
type EntrypointProvider func( sections []string, configs types.ConfigData, logger log.Logger, reg registry.Type, opts ...Option, ) (Entrypoint, error)
EntrypointProvider is the function type to create a new entrypoint. It should create a new config, configure it the run EntrypointFromConfig with it.
type Middleware ¶ added in v0.1.0
type Middleware interface {
// Start/Stop will be called many times, if you require the call once, you have to ensure it on your own.
types.Component
Call(next MiddlewareCallHandler) MiddlewareCallHandler
}
Middleware is an interface that must be implemented by server Middlewares.
type MiddlewareCallHandler ¶ added in v0.1.0
MiddlewareCallHandler is the Handler for unary RPC Calls.
type MiddlewareConfig ¶ added in v0.1.0
type MiddlewareConfig struct {
Plugin string `json:"plugin,omitempty" yaml:"plugin,omitempty"`
}
MiddlewareConfig is the base config for all middlewares.
type MiddlewareProvider ¶ added in v0.1.0
type MiddlewareProvider func( configSection []string, configs types.ConfigData, logger log.Logger, ) (Middleware, error)
MiddlewareProvider is the provider for a middleware, each Middleware must supply this to register itself.
type MiddlewareStreamHandler ¶ added in v0.1.0
MiddlewareStreamHandler is the handler for streaming RPC calls.
type Option ¶
type Option func(EntrypointConfigType)
Option is a functional entrypoint option.
func WithHandlers ¶ added in v0.1.0
func WithHandlers(hs ...RegistrationFunc) Option
WithHandlers appends the given handlers.
func WithMiddlewares ¶ added in v0.1.0
func WithMiddlewares(mws ...Middleware) Option
WithMiddlewares appends the given middlewares.
type RegistrationFunc ¶
type RegistrationFunc func(srv any)
RegistrationFunc is executed to register a handler to a server (entrypoint) passed as srv. srv can be of any of the various server types, should be a pointer.
You can write your own custom registration functions to register extra handlers.
Inside the registration function, you need to convert the server type and assert that you are working with the server type you are expecting, and otherwise no-op. For an example, see the implementation of NewRegistrationFunc.
func NewRegistrationFunc ¶
func NewRegistrationFunc[Tsrv any, Thandler any](register func(Tsrv, Thandler), handler Thandler) RegistrationFunc
NewRegistrationFunc takes a registration function and handler and returns a registration func that can be used with one specific server type.
This function is useful if a user wants to register a non-micro project proto handler. For any internal proto services generated in your project you will already have a pre-defined registration function which only needs the handler implementation.
type Server ¶ added in v0.1.0
type Server struct {
// contains filtered or unexported fields
}
Server is responsible for managing entrypoints. Entrypoints are the actual servers that bind to a port and accept connections. Entrypoints can be dynamically configured.
For more info look at the entrypoint types.
func Provide ¶ added in v0.1.0
func Provide( name types.ServiceName, configs types.ConfigData, logger log.Logger, reg registry.Type, opts ...ConfigOption, ) (Server, error)
Provide creates a new server.
func (*Server) GetEntrypoint ¶ added in v0.1.0
func (s *Server) GetEntrypoint(name string) (Entrypoint, error)
GetEntrypoint returns the requested entrypoint, if present.