web

package
v0.14.0-rc.11 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 11, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
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")
)
View Source
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")
)
View Source
const (
	// ErrEmptyConfig is raised when empty configuration passed into functions that requires it.
	ErrEmptyConfig = internal.Error("empty configuration")
)
View Source
const ErrEmptyListener = internal.Error("empty listener")

ErrEmptyListener is raised when an empty Listener used in the NewListener function or Listener methods.

View Source
const (

	// ErrEmptyLogger is raised when empty logger passed into New function.
	ErrEmptyLogger = internal.Error("empty logger")
)

Variables

View Source
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)
)
View Source
var OpsModule = module.New(NewOpsServer, dig.Group("services")).AppendConstructor(NewOpsConfig)

OpsModule allows import ops http.Server. nolint: gochecknoglobals

Functions

func NewGRPCService

func NewGRPCService(serve *grpc.Server, opts ...GRPCOption) (service.Service, error)

NewGRPCService creates gRPC service with passed gRPC options. If something went wrong it returns an error.

func NewHTTPService

func NewHTTPService(serve *http.Server, opts ...HTTPOption) (service.Service, error)

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

func OpsDefaults(v *viper.Viper)

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 GRPCSkipErrors

func GRPCSkipErrors() GRPCOption

GRPCSkipErrors allows to skip any errors.

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 HTTPSkipErrors

func HTTPSkipErrors() HTTPOption

HTTPSkipErrors allows to skip any errors.

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 Listener

type Listener interface {
	ListenAndServe() error
	Shutdown(context.Context) error
}

Listener service interface.

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 .

func NewOpsConfig

func NewOpsConfig(v *viper.Viper, l *zap.Logger) (*OpsConfig, error)

NewOpsConfig creates OpsConfig and should be moved to settings module in the future.

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

type ProbeChecker func(context.Context) error

ProbeChecker used by ops-server ready and health handler.

type ServerResult

type ServerResult struct {
	dig.Out

	Server service.Service `group:"services"`
}

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL