httpserver

package
v1.9.5 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2022 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrorParamEmpty liberr.CodeError = iota + liberr.MinPkgHttpServer
	ErrorHTTP2Configure
	ErrorPoolAdd
	ErrorPoolValidate
	ErrorPoolListen
	ErrorServerValidate
	ErrorPortUse
	ErrorServerDisabled
	ErrorServerOffline
)

Variables

This section is empty.

Functions

This section is empty.

Types

type FieldType added in v1.5.0

type FieldType uint8
const (
	HandlerDefault           = "default"
	FieldName      FieldType = iota
	FieldBind
	FieldExpose
)

type MapRunPoolServer added in v1.5.0

type MapRunPoolServer func(srv Server)

type MapRunPoolServerConfig added in v1.5.0

type MapRunPoolServerConfig func(cfg ServerConfig)

type MapUpdPoolServer added in v1.5.0

type MapUpdPoolServer func(srv Server) Server

type MapUpdPoolServerConfig added in v1.5.0

type MapUpdPoolServerConfig func(cfg ServerConfig) ServerConfig

type PoolServer added in v1.5.0

type PoolServer interface {
	Add(srv ...Server) (PoolServer, liberr.Error)
	Get(bindAddress string) Server
	Del(bindAddress string) PoolServer
	Has(bindAddress string) bool
	Len() int
	SetLogger(log liblog.FuncLog)

	MapRun(f MapRunPoolServer)
	MapUpd(f MapUpdPoolServer)

	List(fieldFilter, fieldReturn FieldType, pattern, regex string) []string
	Filter(field FieldType, pattern, regex string) PoolServer

	IsRunning(asLeast bool) bool
	WaitNotify(ctx context.Context, cancel context.CancelFunc)

	Listen(handler http.Handler) liberr.Error
	ListenMultiHandler(handler map[string]http.Handler) liberr.Error
	Restart()
	Shutdown()

	StatusInfo(bindAddress string) (name string, release string, hash string)
	StatusHealth(bindAddress string) error
	StatusRoute(prefix string, sts libsts.RouteStatus)
}

func NewPool added in v1.5.0

func NewPool(srv ...Server) PoolServer

type PoolServerConfig added in v1.5.0

type PoolServerConfig []ServerConfig

func (PoolServerConfig) MapRun added in v1.5.0

func (PoolServerConfig) MapUpdate added in v1.5.0

func (PoolServerConfig) PoolServer added in v1.5.0

func (p PoolServerConfig) PoolServer() (PoolServer, liberr.Error)

func (PoolServerConfig) UpdatePoolServer added in v1.5.0

func (p PoolServerConfig) UpdatePoolServer(pSrv PoolServer) (PoolServer, liberr.Error)

func (PoolServerConfig) Validate added in v1.5.0

func (p PoolServerConfig) Validate() liberr.Error

type Server added in v1.5.0

type Server interface {
	SetLogger(log liblog.FuncLog)

	GetConfig() *ServerConfig
	SetConfig(cfg *ServerConfig) bool

	GetName() string
	GetBindable() string
	GetExpose() string
	GetHandlerKey() string

	IsRunning() bool
	IsTLS() bool
	WaitNotify()
	Merge(srv Server) bool

	Listen(handler http.Handler) liberr.Error
	Restart()
	Shutdown()

	StatusInfo() (name string, release string, hash string)
	StatusHealth() error
	StatusComponent() libsts.Component
}

func NewServer

func NewServer(cfg *ServerConfig) Server

type ServerConfig added in v1.5.0

type ServerConfig struct {

	// Name is the name of the current server
	// the configuration allow multipke server, which each one must be identify by a name
	// If not defined, will use the listen address
	Name string `mapstructure:"name" json:"name" yaml:"name" toml:"name" validate:"required"`

	// Listen is the local address (ip, hostname, unix socket, ...) with a port
	// The server will bind with this address only and listen for the port defined
	Listen string `mapstructure:"listen" json:"listen" yaml:"listen" toml:"listen" validate:"required,hostname_port"`

	// Expose is the address use to call this server. This can be allow to use a single fqdn to multiple server"
	Expose string `mapstructure:"expose" json:"expose" yaml:"expose" toml:"expose" validate:"required,url"`

	// HandlerKeys is an options to associate current server with a specifc handler defined by the key
	// This allow to defined multiple server in only one config for different handler to start multiple api
	HandlerKeys string `mapstructure:"handler_keys" json:"handler_keys" yaml:"handler_keys" toml:"handler_keys"`

	// Enabled allow to disable a server without clean his configuration
	Disabled bool `mapstructure:"disabled" json:"disabled" yaml:"disabled" toml:"disabled"`

	// Mandator
	// y defined if the component for status is mandatory or not
	Status libsts.ConfigStatus `mapstructure:"status" json:"status" yaml:"status" toml:"status"`

	// TLSMandatory is a flag to defined that TLS must be valid to start current server.
	TLSMandatory bool `mapstructure:"tls_mandatory" json:"tls_mandatory" yaml:"tls_mandatory" toml:"tls_mandatory"`

	// TLS is the tls configuration for this server.
	// To allow tls on this server, at least the TLS Config option InheritDefault must be at true and the default TLS config must be set.
	// If you don't want any tls config, just omit or set an empty struct.
	TLS libtls.Config `mapstructure:"tls" json:"tls" yaml:"tls" toml:"tls"`

	// ReadTimeout is the maximum duration for reading the entire
	// request, including the body.
	//
	// Because ReadTimeout does not let Handlers make per-request
	// decisions on each request body's acceptable deadline or
	// upload rate, most users will prefer to use
	// ReadHeaderTimeout. It is valid to use them both.
	ReadTimeout time.Duration `mapstructure:"read_timeout" json:"read_timeout" yaml:"read_timeout" toml:"read_timeout"`

	// ReadHeaderTimeout is the amount of time allowed to read
	// request headers. The connection's read deadline is reset
	// after reading the headers and the Handler can decide what
	// is considered too slow for the body. If ReadHeaderTimeout
	// is zero, the value of ReadTimeout is used. If both are
	// zero, there is no timeout.
	ReadHeaderTimeout time.Duration `mapstructure:"read_header_timeout" json:"read_header_timeout" yaml:"read_header_timeout" toml:"read_header_timeout"`

	// WriteTimeout is the maximum duration before timing out
	// writes of the response. It is reset whenever a new
	// request's header is read. Like ReadTimeout, it does not
	// let Handlers make decisions on a per-request basis.
	WriteTimeout time.Duration `mapstructure:"write_timeout" json:"write_timeout" yaml:"write_timeout" toml:"write_timeout"`

	// MaxHeaderBytes controls the maximum number of bytes the
	// server will read parsing the request header's keys and
	// values, including the request line. It does not limit the
	// size of the request body.
	// If zero, DefaultMaxHeaderBytes is used.
	MaxHeaderBytes int `mapstructure:"max_header_bytes" json:"max_header_bytes" yaml:"max_header_bytes" toml:"max_header_bytes"`

	// MaxHandlers limits the number of http.Handler ServeHTTP goroutines
	// which may run at a time over all connections.
	// Negative or zero no limit.
	MaxHandlers int `mapstructure:"max_handlers" json:"max_handlers" yaml:"max_handlers" toml:"max_handlers"`

	// MaxConcurrentStreams optionally specifies the number of
	// concurrent streams that each client may have open at a
	// time. This is unrelated to the number of http.Handler goroutines
	// which may be active globally, which is MaxHandlers.
	// If zero, MaxConcurrentStreams defaults to at least 100, per
	// the HTTP/2 spec's recommendations.
	MaxConcurrentStreams uint32 `json:"max_concurrent_streams" json:"max_concurrent_streams" yaml:"max_concurrent_streams" toml:"max_concurrent_streams"`

	// MaxReadFrameSize optionally specifies the largest frame
	// this server is willing to read. A valid value is between
	// 16k and 16M, inclusive. If zero or otherwise invalid, a
	// default value is used.
	MaxReadFrameSize uint32 `json:"max_read_frame_size" json:"max_read_frame_size" yaml:"max_read_frame_size" toml:"max_read_frame_size"`

	// PermitProhibitedCipherSuites, if true, permits the use of
	// cipher suites prohibited by the HTTP/2 spec.
	PermitProhibitedCipherSuites bool `` /* 155-byte string literal not displayed */

	// IdleTimeout specifies how long until idle clients should be
	// closed with a GOAWAY frame. PING frames are not considered
	// activity for the purposes of IdleTimeout.
	IdleTimeout time.Duration `json:"idle_timeout" json:"idle_timeout" yaml:"idle_timeout" toml:"idle_timeout"`

	// MaxUploadBufferPerConnection is the size of the initial flow
	// control window for each connections. The HTTP/2 spec does not
	// allow this to be smaller than 65535 or larger than 2^32-1.
	// If the value is outside this range, a default value will be
	// used instead.
	MaxUploadBufferPerConnection int32 `` /* 159-byte string literal not displayed */

	// MaxUploadBufferPerStream is the size of the initial flow control
	// window for each stream. The HTTP/2 spec does not allow this to
	// be larger than 2^32-1. If the value is zero or larger than the
	// maximum, a default value will be used instead.
	MaxUploadBufferPerStream int32 `` /* 143-byte string literal not displayed */
	// contains filtered or unexported fields
}

nolint #maligned

func (*ServerConfig) Clone added in v1.5.7

func (c *ServerConfig) Clone() ServerConfig

func (*ServerConfig) GetExpose added in v1.5.0

func (c *ServerConfig) GetExpose() *url.URL

func (*ServerConfig) GetHandlerKey added in v1.5.7

func (c *ServerConfig) GetHandlerKey() string

func (*ServerConfig) GetListen added in v1.5.0

func (c *ServerConfig) GetListen() *url.URL

func (*ServerConfig) GetTLS added in v1.5.0

func (c *ServerConfig) GetTLS() (libtls.TLSConfig, liberr.Error)

func (*ServerConfig) IsTLS added in v1.5.0

func (c *ServerConfig) IsTLS() bool

func (*ServerConfig) Server added in v1.5.0

func (c *ServerConfig) Server() Server

func (*ServerConfig) SetDefaultTLS added in v1.5.0

func (c *ServerConfig) SetDefaultTLS(f func() libtls.TLSConfig)

func (*ServerConfig) SetParentContext added in v1.5.0

func (c *ServerConfig) SetParentContext(f func() context.Context)

func (*ServerConfig) Validate added in v1.5.0

func (c *ServerConfig) Validate() liberr.Error

Jump to

Keyboard shortcuts

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