server

package module
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2024 License: MIT Imports: 21 Imported by: 1

README

HTTP Server

Installation

Install Server
go get -u github.com/gowool/server
Install Fx Options
go get -u github.com/gowool/server/fx

License

Distributed under MIT License, please see license file within the code for more details.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateCertPool

func CreateCertPool(rootCa string) (*x509.CertPool, error)

func DefaultTLSConfig

func DefaultTLSConfig() *tls.Config

func IssueCertificates

func IssueCertificates(cacheDir, email string, challengeType ChallengeType, domains []string, useProduction bool, altHTTPPort, altTLSAlpnPort int, logger *zap.Logger) (*tls.Config, error)

func Port

func Port(address string) int

Types

type AcmeConfig

type AcmeConfig struct {
	// directory to save the certificates, le_certs default
	CacheDir string `json:"cache_dir" yaml:"cache_dir"`

	// User email, mandatory
	Email string `json:"email" yaml:"email"`

	// supported values: http-01, tlsalpn-01
	ChallengeType ChallengeType `json:"challenge_type" yaml:"challenge_type"`

	// The alternate port to use for the ACME HTTP challenge
	AltHTTPPort int `json:"alt_http_port" yaml:"alt_http_port"`

	// The alternate port to use for the ACME TLS-ALPN
	AltTLSALPNPort int `json:"alt_tlsalpn_port" yaml:"alt_tlsalpn_port"`

	// Use LE production endpoint or staging
	UseProductionEndpoint bool `json:"use_production_endpoint" yaml:"use_production_endpoint"`

	// Domains to obtain certificates
	Domains []string `json:"domains" yaml:"domains"`
}

func (*AcmeConfig) InitDefaults

func (cfg *AcmeConfig) InitDefaults() error

type ChallengeType

type ChallengeType string
const (
	HTTP01    ChallengeType = "http-01"
	TLSAlpn01 ChallengeType = "tlsalpn-01"
)

type ClientAuthType

type ClientAuthType string
const (
	NoClientCert               ClientAuthType = "no_client_cert"
	RequestClientCert          ClientAuthType = "request_client_cert"
	RequireAnyClientCert       ClientAuthType = "require_any_client_cert"
	VerifyClientCertIfGiven    ClientAuthType = "verify_client_cert_if_given"
	RequireAndVerifyClientCert ClientAuthType = "require_and_verify_client_cert"
)

type Config

type Config struct {
	// Host and port to handle as http server.
	Address string `json:"address,omitempty" yaml:"address,omitempty"`

	// Redirect when enabled forces all http connections to switch to https.
	Redirect bool `json:"redirect,omitempty" yaml:"redirect,omitempty"`

	// ReadTimeout is the maximum duration for reading the entire
	// request, including the body. A zero or negative value means
	// there will be no timeout.
	//
	// 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 `json:"read_timeout,omitempty" yaml:"read_timeout,omitempty"`

	// 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 zero, the value of
	// ReadTimeout is used. If negative, or if zero and ReadTimeout
	// is zero or negative, there is no timeout.
	ReadHeaderTimeout time.Duration `json:"read_header_timeout,omitempty" yaml:"read_header_timeout,omitempty"`

	// 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.
	// A zero or negative value means there will be no timeout.
	WriteTimeout time.Duration `json:"write_timeout,omitempty" yaml:"write_timeout,omitempty"`

	// IdleTimeout is the maximum amount of time to wait for the
	// next request when keep-alives are enabled. If zero, the value
	// of ReadTimeout is used. If negative, or if zero and ReadTimeout
	// is zero or negative, there is no timeout.
	IdleTimeout time.Duration `json:"idle_timeout,omitempty" yaml:"idle_timeout,omitempty"`

	// 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 `json:"max_header_bytes,omitempty" yaml:"max_header_bytes,omitempty"`

	// H2C defines http/2 server options.
	H2C H2CConfig `json:"h2c,omitempty" yaml:"h2c,omitempty"`

	// SSL defines https server options.
	SSL *SSLConfig `json:"ssl,omitempty" yaml:"ssl,omitempty"`
}

func (*Config) EnableTLS

func (cfg *Config) EnableTLS() bool

func (*Config) InitDefaults

func (cfg *Config) InitDefaults() error

func (*Config) Valid

func (cfg *Config) Valid() error

type H2CConfig

type H2CConfig struct {
	// MaxConcurrentStreams defaults to 128.
	MaxConcurrentStreams uint `json:"max_concurrent_streams,omitempty" yaml:"max_concurrent_streams,omitempty"`
}

func (*H2CConfig) InitDefaults

func (cfg *H2CConfig) InitDefaults()

type HTTP

type HTTP struct {
	// contains filtered or unexported fields
}

func NewHTTP

func NewHTTP(cfg Config, handler http.Handler, logger *zap.Logger) *HTTP

func (*HTTP) Start

func (s *HTTP) Start() error

func (*HTTP) Stop

func (s *HTTP) Stop(ctx context.Context) error

type HTTPS

type HTTPS struct {
	// contains filtered or unexported fields
}

func NewHTTPS

func NewHTTPS(cfg Config, handler http.Handler, logger *zap.Logger) (*HTTPS, error)

func (*HTTPS) Start

func (s *HTTPS) Start() error

func (*HTTPS) Stop

func (s *HTTPS) Stop(ctx context.Context) error

type SSLConfig

type SSLConfig struct {
	// Address to listen as HTTPS server, defaults to 0.0.0.0:443.
	Address string `json:"address,omitempty" yaml:"address,omitempty"`

	// Acme configuration
	Acme *AcmeConfig `json:"acme,omitempty" yaml:"acme,omitempty"`

	// Key defined private server key.
	Key string `json:"key,omitempty" yaml:"key,omitempty"`

	// Cert is https certificate.
	Cert string `json:"cert,omitempty" yaml:"cert,omitempty"`

	// RootCA file
	RootCA string `json:"root_ca,omitempty" yaml:"root_ca,omitempty"`

	// AuthType mTLS auth
	AuthType ClientAuthType `json:"auth_type,omitempty" yaml:"auth_type,omitempty"`

	// H3 enable HTTP3
	H3 bool `json:"h3,omitempty" yaml:"h3,omitempty"`
}

func (*SSLConfig) Enable

func (cfg *SSLConfig) Enable() bool

func (*SSLConfig) EnableACME

func (cfg *SSLConfig) EnableACME() bool

func (*SSLConfig) InitDefaults

func (cfg *SSLConfig) InitDefaults() error

func (*SSLConfig) Valid

func (cfg *SSLConfig) Valid() error

type Server

type Server struct {
	// contains filtered or unexported fields
}

func NewServer

func NewServer(cfg Config, handler http.Handler, logger *zap.Logger) (*Server, error)

func (*Server) Start

func (s *Server) Start(ctx context.Context) error

func (*Server) Stop

func (s *Server) Stop(ctx context.Context) error

Directories

Path Synopsis
fx module

Jump to

Keyboard shortcuts

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