Documentation
¶
Index ¶
- type HTTPConfLoader
- type HttpServerConfig
- type HttpServerConfigOption
- func HttpErrorLog(errLog *log.Logger) HttpServerConfigOption
- func HttpHandler(handler http.Handler) HttpServerConfigOption
- func HttpMaxHeaderBytes(count int) HttpServerConfigOption
- func HttpReadHeaderTimeout(timeout time.Duration) HttpServerConfigOption
- func HttpReadTimeout(timeout time.Duration) HttpServerConfigOption
- type HttpServerConfigProtos
- type HttpServerLoader
- type HttpServerLoaderOption
- type Loader
- type TlsConfigLoader
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type HTTPConfLoader ¶
type HTTPConfLoader Loader[HttpServerConfig]
type HttpServerConfig ¶
type HttpServerConfig struct {
Protos *http.Protocols
Hostname string // The hostname as given OR ip address if no hostname was given.
BindAddr string // The address to bind to
Port uint16 // The port to bind to
RemoteAddress string // The address clients should connect to. This is generally [proto]://[hostname]:[port] (although port is omitted if it is the standard http[s] port)
TlsConf *tls.Config // TLS config to use. If tls was disabled you can still use this and it will correctly be a non-TLS connetion.
// contains filtered or unexported fields
}
HttpServerConfig is the struct produced by the loader. It has pretty much everything needed to create an http.Server
func (HttpServerConfig) NewHttpServer ¶
func (c HttpServerConfig) NewHttpServer() *http.Server
NewHttpServer returns an *http.Http configured according to HttpServerConfig's fields.
Calling (HttpServerConfig.NewHttpServer()).ListenAndServe() should do what you want most of the time unless you have specific needs.
func (HttpServerConfig) With ¶
func (c HttpServerConfig) With(o HttpServerConfigOption) HttpServerConfig
type HttpServerConfigOption ¶
type HttpServerConfigOption func(HttpServerConfig) HttpServerConfig
func HttpErrorLog ¶
func HttpErrorLog(errLog *log.Logger) HttpServerConfigOption
func HttpHandler ¶
func HttpHandler(handler http.Handler) HttpServerConfigOption
func HttpMaxHeaderBytes ¶
func HttpMaxHeaderBytes(count int) HttpServerConfigOption
func HttpReadHeaderTimeout ¶
func HttpReadHeaderTimeout(timeout time.Duration) HttpServerConfigOption
func HttpReadTimeout ¶
func HttpReadTimeout(timeout time.Duration) HttpServerConfigOption
type HttpServerConfigProtos ¶
type HttpServerConfigProtos int
Loading HTTP and TLS config from files is not that bad, but this removes a lot of boilerplate that exists in every web-based project.
const ( HTTP HttpServerConfigProtos = iota HTTPS HTTP2 UNENCRYPTEDHTTP2 )
func (HttpServerConfigProtos) GetHttpProtos ¶
func (p HttpServerConfigProtos) GetHttpProtos() *http.Protocols
func (HttpServerConfigProtos) String ¶
func (p HttpServerConfigProtos) String() string
type HttpServerLoader ¶
type HttpServerLoader struct {
Protocol optional.Option[HttpServerConfigProtos] // Default behavior is to set this based on Tls.TlsEnabled.
Hostname optional.Str
BindAddr optional.Str // an empty string will cause us to bind to all interfaces. Defaults to 127.0.0.1
BindPort optional.Uint16 // Defaults to 80 for HTTP, 443 for HTTPS
Tls Loader[*tls.Config]
ReadTimeout optional.Duration // Defaults to 0. Same as http.Server
ReadHeaderTimeout optional.Duration // Defaults to 0. Same as http.Server
MaxHeaderBytes optional.Int
// contains filtered or unexported fields
}
HttpServerLoader gets parameters from the environment and user overrides in order to produce an HttpServerConfig struct. The HttpServerConfig struct in turn can be used to create a new http.Server.
func (*HttpServerLoader) Previous ¶
func (l *HttpServerLoader) Previous() HttpServerConfig
func (*HttpServerLoader) Update ¶
func (l *HttpServerLoader) Update() (result HttpServerConfig, err error)
func (HttpServerLoader) With ¶
func (c HttpServerLoader) With(o HttpServerLoaderOption) HttpServerLoader
type HttpServerLoaderOption ¶
type HttpServerLoaderOption func(HttpServerLoader) HttpServerLoader
func HttpLoaderErrorLog ¶
func HttpLoaderErrorLog(errLog *log.Logger) HttpServerLoaderOption
func HttpLoaderHandler ¶
func HttpLoaderHandler(handler http.Handler) HttpServerLoaderOption
type TlsConfigLoader ¶
type TlsConfigLoader struct {
TlsEnabled optional.Bool
ServerName optional.Str
PrivateKey file.PrivateKey `default:"tls/key.pem"`
Certificate file.Cert `default:"tls/cert.pem"`
InsecureSkipVerify optional.Bool `default:"false"`
// contains filtered or unexported fields
}
func (*TlsConfigLoader) Previous ¶
func (l *TlsConfigLoader) Previous() *tls.Config