Documentation ¶
Overview ¶
Package drpc provides the drpc server for go-orb.
Index ¶
- Constants
- Variables
- func DefaultCodecWhitelist() []string
- func WithDefaults(options ...Option) server.Option
- func WithEntrypoint(options ...Option) server.Option
- type Config
- type Option
- func WithAddress(address string) Option
- func WithConfig(config Config) Option
- func WithListener(l net.Listener) Option
- func WithLogLevel(level slog.Level) Option
- func WithLogPlugin(plugin string) Option
- func WithName(name string) Option
- func WithRegistration(name string, registration server.RegistrationFunc) Option
- type Server
- func (s *Server) AddEndpoint(name string)
- func (s *Server) Address() string
- func (s *Server) EntrypointID() string
- func (s *Server) Name() string
- func (s *Server) Register(register orbserver.RegistrationFunc)
- func (s *Server) Router() *drpcmux.Mux
- func (s *Server) Start() error
- func (s *Server) Stop(_ context.Context) error
- func (s *Server) String() string
- func (s *Server) Transport() string
- func (s *Server) Type() string
Constants ¶
const ( // DefaultAddress to use for new dRPC servers. // If set to "random", the default, a random address will be selected, // preferably on a private interface (XX subet). TODO: implement. DefaultAddress = "[::]:8381" // DefaultMaxConcurrentStreams for HTTP2. DefaultMaxConcurrentStreams = 512 // DefaultReadTimeout see net/http pkg for more details. DefaultReadTimeout = 5 * time.Second // DefaultWriteTimeout see net/http pkg for more details. DefaultWriteTimeout = 5 * time.Second // DefaultIdleTimeout see net/http pkg for more details. DefaultIdleTimeout = 5 * time.Second // DefaultStopTimeout sets the timeout for ServerHertz.Stop(). DefaultStopTimeout = time.Second // DefaultConfigSection is the section key used in config files used to // configure the server options. DefaultConfigSection = Plugin )
const Plugin = "drpc"
Plugin is the plugin name.
Variables ¶
var ( // ErrInvalidConfigType is returned when you provided an invalid config type. ErrInvalidConfigType = errors.New("drpc server: invalid config type provided, not of type drpc.Config") )
Errors.
Functions ¶
func DefaultCodecWhitelist ¶
func DefaultCodecWhitelist() []string
DefaultCodecWhitelist is the default allowed list of codecs to be used for HTTP request encoding/decoding. This means that if any of these plugins are registered, they will be included in the server's available codecs. If they are not registered, the server will not be able to handle these formats.
func WithDefaults ¶
WithDefaults sets default options to use on the creation of new HTTP entrypoints.
func WithEntrypoint ¶
WithEntrypoint adds an HTTP entrypoint with the provided options.
Types ¶
type Config ¶
type Config struct { // Name is the entrypoint name. // // The default name is 'http-<random uuid>' Name string `json:"name" yaml:"name"` // Listener can be used to provide your own Listener, when in use `Address` is obsolete. Listener net.Listener `json:"-" yaml:"-"` // Address to listen on. // TODO(davincible): implement this, and the address method. // 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"` // HandlerRegistrations are all handler registration functions that will be // registered to the server upon startup. // // You can statically add handlers by using the fuctional server options. // Optionally, you can dynamically add handlers by registering them to the // Handlers global, and setting them explicitly in the config. HandlerRegistrations server.HandlerRegistrations `json:"handlers" yaml:"handlers"` // Logger allows you to dynamically change the log level and plugin for a // specific entrypoint. Logger struct { Level slog.Level `json:"level,omitempty" yaml:"level,omitempty"` // TODO(davincible): change with custom level Plugin string `json:"plugin,omitempty" yaml:"plugin,omitempty"` } `json:"logger" yaml:"logger"` }
Config provides options to the entrypoint.
func (*Config) ApplyOptions ¶
ApplyOptions applies a set of options to the config.
func (Config) Copy ¶
func (c Config) Copy() server.EntrypointConfig
Copy creates a copy of the entrypoint config.
func (Config) GetAddress ¶
GetAddress returns the entrypoint address.
type Option ¶
type Option func(*Config)
Option is a functional option to provide custom values to the config.
func WithAddress ¶
WithAddress specifies the address to listen on. If you want to listen on all interfaces use the format ":8080" If you want to listen on a specific interface/address use the full IP.
func WithConfig ¶
WithConfig will set replace the server config with config provided as argument. Warning: any options applied previous to this option will be overwritten by the contents of the config provided here.
func WithListener ¶
WithListener sets the entrypoints listener. This overwrites `Address`.
func WithLogLevel ¶
WithLogLevel changes the log level from the inherited logger.
func WithLogPlugin ¶
WithLogPlugin changes the log level from the inherited logger.
func WithName ¶
WithName sets the entrypoint name. The default name is in the format of 'http-<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 WithRegistration ¶
func WithRegistration(name string, registration server.RegistrationFunc) Option
WithRegistration adds a named registration function to the config. The name set here allows you to dynamically add this handler to entrypoints through a config.
Registration functions are used to register handlers to a server.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is the drpc Server for go-orb.
func ProvideServer ¶
func ProvideServer( _ types.ServiceName, logger log.Logger, reg registry.Type, cfg Config, options ...Option, ) (*Server, error)
ProvideServer creates a new entrypoint for a single address. You can create multiple entrypoints for multiple addresses and ports.
func (*Server) AddEndpoint ¶
AddEndpoint add's an endpoint to the internal list. This is used by the Register() callback function.
func (*Server) Address ¶
Address returns the address the entrypoint is listening on, for example: [::]:8381.
func (*Server) EntrypointID ¶
EntrypointID returns the id (uuid) of this entrypoint in the registry.
func (*Server) Register ¶
func (s *Server) Register(register orbserver.RegistrationFunc)
Register executes a registration function on the entrypoint.