Documentation
¶
Index ¶
- Constants
- Variables
- func NewGRPCService(serve *grpc.Server, opts ...GRPCOption) (service.Service, error)
- func NewHTTPService(serve *http.Server, opts ...HTTPOption) (service.Service, error)
- func NewListener(lis Listener, opts ...ListenerOption) (service.Service, error)
- func NewOpsServer(cfg *OpsConfig, probe OpsProbeParams) (service.Service, error)
- func OpsDefaults(v *viper.Viper)
- func PrepareHTTPService(cfg HTTPConfig) (service.Service, error)
- type APIParams
- type GRPCOption
- type HTTPConfig
- type HTTPOption
- type HTTPParams
- type Listener
- type ListenerOption
- type OpsConfig
- type OpsProbeParams
- type ProbeChecker
- type ServerResult
Constants ¶
const ( // ErrEmptyGRPCServer is raised when called NewGRPCService // or gRPC methods with empty grpc.Server. ErrEmptyGRPCServer = internal.Error("empty gRPC server") // ErrEmptyGRPCAddress is raised when passed empty address to NewGRPCService. ErrEmptyGRPCAddress = internal.Error("empty gRPC address") )
const ( // ErrEmptyHTTPServer is raised when called New or httpService methods with empty http.Server. ErrEmptyHTTPServer = internal.Error("empty http server") // ErrEmptyHTTPAddress is raised when passed empty address to NewHTTPService. ErrEmptyHTTPAddress = internal.Error("empty http address") )
const ( // ErrEmptyConfig is raised when empty configuration passed into functions that requires it. ErrEmptyConfig = internal.Error("empty configuration") )
const ErrEmptyListener = internal.Error("empty listener")
ErrEmptyListener is raised when an empty Listener used in the NewListener function or Listener methods.
const ( // ErrEmptyLogger is raised when empty logger passed into New function. ErrEmptyLogger = internal.Error("empty logger") )
Variables ¶
var ( // DefaultServersModule of web base structs. // nolint:gochecknoglobals DefaultServersModule = module.Combine( DefaultGRPCModule, OpsModule, APIModule, ) // APIModule defines API server module. // nolint:gochecknoglobals APIModule = module.New(NewAPIServer) // DefaultGRPCModule defines default gRPC server module. // nolint:gochecknoglobals DefaultGRPCModule = module.New(newDefaultGRPCServer) )
var OpsModule = module.New(NewOpsServer, dig.Group("services")).AppendConstructor(NewOpsConfig)
OpsModule allows import ops http.Server. nolint: gochecknoglobals
Functions ¶
func NewGRPCService ¶
NewGRPCService creates gRPC service with passed gRPC options. If something went wrong it returns an error.
func NewHTTPService ¶
NewHTTPService creates Service from http.Server and HTTPOption's.
func NewListener ¶
func NewListener(lis Listener, opts ...ListenerOption) (service.Service, error)
NewListener creates new Listener service and applies passed options to it.
func NewOpsServer ¶
func NewOpsServer(cfg *OpsConfig, probe OpsProbeParams) (service.Service, error)
NewOpsServer creates ops server.
func OpsDefaults ¶
OpsDefaults allows setting default settings for ops server.
func PrepareHTTPService ¶
func PrepareHTTPService(cfg HTTPConfig) (service.Service, error)
PrepareHTTPService creates http.Server as service.Service.
Types ¶
type APIParams ¶
type APIParams struct {
dig.In
Config *viper.Viper
Logger *zap.Logger
Handler http.Handler `optional:"true"`
Listener net.Listener `name:"api_listener" optional:"true"`
}
APIParams struct.
type GRPCOption ¶
type GRPCOption func(g *gRPC)
GRPCOption allows changing default gRPC service settings.
func GRPCListenAddress ¶
func GRPCListenAddress(addr string) GRPCOption
GRPCListenAddress allows to change network for net.Listener.
func GRPCListenNetwork ¶
func GRPCListenNetwork(network string) GRPCOption
GRPCListenNetwork allows to change default (tcp) network for net.Listener.
func GRPCListener ¶
func GRPCListener(lis net.Listener) GRPCOption
GRPCListener allows to set custom net.Listener.
func GRPCName ¶
func GRPCName(name string) GRPCOption
GRPCName allows set name for the http-service.
func GRPCWithLogger ¶
func GRPCWithLogger(l *zap.Logger) GRPCOption
GRPCWithLogger changes default logger.
type HTTPConfig ¶
type HTTPConfig struct {
Logger *zap.Logger `mapstructure:"-"`
Handler http.Handler `mapstructure:"-"`
Name string `mapstructure:"name"`
Address string `mapstructure:"address"`
Network string `mapstructure:"network"`
ReadTimeout time.Duration `mapstructure:"read_timeout"`
ReadHeaderTimeout time.Duration `mapstructure:"read_header_timeout"`
WriteTimeout time.Duration `mapstructure:"write_timeout"`
IdleTimeout time.Duration `mapstructure:"idle_timeout"`
MaxHeaderBytes int `mapstructure:"max_header_bytes"`
}
HTTPConfig .
type HTTPOption ¶
type HTTPOption func(s *httpService)
HTTPOption interface that allows to change default http-service options.
func HTTPListenAddress ¶
func HTTPListenAddress(address string) HTTPOption
HTTPListenAddress allows changing network for net.Listener. By default, it takes address from http.Server.
func HTTPListenNetwork ¶
func HTTPListenNetwork(network string) HTTPOption
HTTPListenNetwork allows changing default (tcp) network for net.Listener.
func HTTPListener ¶
func HTTPListener(lis net.Listener) HTTPOption
HTTPListener allows to set custom net.Listener.
func HTTPName ¶
func HTTPName(name string) HTTPOption
HTTPName allows set name for the http-service.
func HTTPWithLogger ¶
func HTTPWithLogger(l *zap.Logger) HTTPOption
HTTPWithLogger allows to set logger.
type HTTPParams ¶
type HTTPParams struct {
dig.In
Config *viper.Viper
Logger *zap.Logger
Name string `name:"http_name" optional:"true"`
Key string `name:"http_config" optional:"true"`
Handler http.Handler `name:"http_handler" optional:"true"`
Listener net.Listener `name:"http_listener" optional:"true"`
}
HTTPParams struct.
type ListenerOption ¶
type ListenerOption func(l *listener)
ListenerOption options that allows to change default settings for Listener service.
func ListenerIgnoreError ¶
func ListenerIgnoreError(errors ...error) ListenerOption
ListenerIgnoreError allows for ignoring all passed errors.
func ListenerName ¶
func ListenerName(v string) ListenerOption
ListenerName allows changing the default listener name.
func ListenerSkipErrors ¶
func ListenerSkipErrors() ListenerOption
ListenerSkipErrors allows for ignoring all raised errors.
func ListenerWithLogger ¶
func ListenerWithLogger(log *zap.Logger) ListenerOption
ListenerWithLogger allows to set custom zap.Logger.
type OpsConfig ¶
type OpsConfig struct {
HTTPConfig `mapstructure:",squash"`
DisableMetrics bool `mapstructure:"disable_metrics"`
DisableProfile bool `mapstructure:"disable_pprof"`
DisableHealthy bool `mapstructure:"disable_healthy"`
}
OpsConfig .
type OpsProbeParams ¶
type OpsProbeParams struct {
dig.In
HealthProbes []ProbeChecker `group:"health_probes"`
ReadyProbes []ProbeChecker `group:"ready_probes"`
}
OpsProbeParams allows setting health and ready probes for ops server.
type ProbeChecker ¶
ProbeChecker used by ops-server ready and health handler.
type ServerResult ¶
ServerResult struct.
func NewAPIServer ¶
func NewAPIServer(p APIParams) (ServerResult, error)
NewAPIServer creates api server by http.Handler from DI container.
func NewHTTPServer ¶
func NewHTTPServer(p HTTPParams) (ServerResult, error)
NewHTTPServer creates http-server that will be embedded into multiple server.