server

package module
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2025 License: MIT Imports: 20 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 DefaultTLSConfig

func DefaultTLSConfig() *tls.Config

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"`

	// 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"`

	HTTPChallenge *HTTPChallengeConfig `json:"httpChallenge" yaml:"httpChallenge"`

	TLSChallenge bool `json:"tlsChallenge" yaml:"tlsChallenge"`

	DNSChallenge *DNSChallengeConfig `json:"dnsChallenge" yaml:"dnsChallenge"`
	// contains filtered or unexported fields
}

func (*AcmeConfig) Config added in v0.1.0

func (cfg *AcmeConfig) Config(key string, mCfg EntryPointsConfig, logger *zap.Logger) *certmagic.Config

type CertificateConfig added in v0.1.0

type CertificateConfig struct {
	CertFile string `json:"certFile,omitempty" yaml:"certFile,omitempty"`
	KeyFile  string `json:"keyFile,omitempty" yaml:"keyFile,omitempty"`
}

func (CertificateConfig) Certificate added in v0.1.0

func (cfg CertificateConfig) Certificate() (tls.Certificate, error)

type ClientAuthConfig added in v0.1.0

type ClientAuthConfig struct {
	ClientAuthType ClientAuthType `json:"clientAuthType,omitempty" yaml:"clientAuthType,omitempty"`
	CaFiles        []string       `json:"caFiles,omitempty" yaml:"caFiles,omitempty"`
}

func (*ClientAuthConfig) CertPool added in v0.1.0

func (cfg *ClientAuthConfig) CertPool() (*x509.CertPool, error)

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"
)

func (ClientAuthType) TLSClientAuth added in v0.1.0

func (t ClientAuthType) TLSClientAuth() tls.ClientAuthType

type DNSChallengeConfig added in v0.1.0

type DNSChallengeConfig struct {
	Provider DNSProviderType   `json:"provider" yaml:"provider"`
	APIToken string            `json:"apiToken" yaml:"apiToken"`
	Metadata map[string]string `json:"metadata" yaml:"metadata"`
}

type DNSProviderType added in v0.1.0

type DNSProviderType string
const CloudflareProvider DNSProviderType = "cloudflare"

type EntryPoint added in v0.1.0

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

func NewEntryPoint added in v0.1.0

func NewEntryPoint(name string, cfg EntryPointsConfig, handler http.Handler, logger *zap.Logger) (*EntryPoint, error)

func (*EntryPoint) Start added in v0.1.0

func (ep *EntryPoint) Start() error

func (*EntryPoint) Stop added in v0.1.0

func (ep *EntryPoint) Stop(ctx context.Context) error

type EntryPointConfig added in v0.1.0

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

	// HTTP2 defines http/2 server options.
	HTTP2 HTTP2Config `json:"http2,omitempty" yaml:"http2,omitempty"`

	// HTTP3 enables HTTP/3 protocol on the entryPoint. HTTP/3 requires a TCP entryPoint,
	// as HTTP/3 always starts as a TCP connection that then gets upgraded to UDP.
	// In most scenarios, this entryPoint is the same as the one used for TLS traffic.
	HTTP3 *HTTP3Config `json:"http3,omitempty" yaml:"http3,omitempty"`

	Transport TransportConfig `json:"transport,omitempty" yaml:"transport,omitempty"`

	HTTP HTTPConfig `json:"http,omitempty" yaml:"http,omitempty"`
}

type EntryPointsConfig added in v0.1.0

type EntryPointsConfig map[string]EntryPointConfig

type HTTP2Config added in v0.1.0

type HTTP2Config struct {
	// MaxConcurrentStreams specifies the number of concurrent
	// streams per connection that each client is allowed to initiate.
	// The MaxConcurrentStreams value must be greater than zero, defaults to 250.
	MaxConcurrentStreams uint `json:"maxConcurrentStreams,omitempty" yaml:"maxConcurrentStreams,omitempty"`
}

type HTTP3Config added in v0.1.0

type HTTP3Config struct {
	// AdvertisedPort defines which UDP port to advertise as the HTTP/3 authority.
	// It defaults to the entryPoint's address port. It can be used to override
	// the authority in the alt-svc header.
	AdvertisedPort uint `json:"advertisedPort,omitempty" yaml:"advertisedPort,omitempty"`
}

type HTTPChallengeConfig added in v0.1.0

type HTTPChallengeConfig struct {
	EntryPoint string `json:"entryPoint" yaml:"entryPoint"`
}

type HTTPConfig added in v0.1.0

type HTTPConfig struct {
	Redirection *RedirectionConfig `json:"redirection,omitempty" yaml:"redirection,omitempty"`
	TLS         *TLSConfig         `json:"tls,omitempty" yaml:"tls,omitempty"`
}

type RedirectionConfig added in v0.1.0

type RedirectionConfig struct {
	EntryPoint struct {
		// To the target element, it can be:
		//   - an entry point name (ex: websecure)
		//   - a port (:443)
		// defaults: :443
		To string `json:"to,omitempty" yaml:"to,omitempty"`

		// Scheme the redirection target scheme, defaults to `https`
		Scheme string `json:"scheme,omitempty" yaml:"scheme,omitempty"`

		// Permanent to apply a permanent redirection
		Permanent bool `json:"permanent,omitempty" yaml:"permanent,omitempty"`
	} `json:"entryPoint,omitempty" yaml:"entryPoint,omitempty"`
}

type Server

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

func NewServer

func NewServer(cfg EntryPointsConfig, 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

type TLSConfig added in v0.1.0

type TLSConfig struct {
	InsecureSkipVerify bool                `json:"insecureSkipVerify,omitempty" yaml:"insecureSkipVerify,omitempty"`
	Certificates       []CertificateConfig `json:"certificates,omitempty" yaml:"certificates,omitempty"`
	ClientAuth         *ClientAuthConfig   `json:"clientAuth,omitempty" yaml:"clientAuth,omitempty"`
	Acme               *AcmeConfig         `json:"acme,omitempty" yaml:"acme,omitempty"`
}

type TransportConfig added in v0.1.0

type TransportConfig struct {
	// 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:"readTimeout,omitempty" yaml:"readTimeout,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:"readHeaderTimeout,omitempty" yaml:"readHeaderTimeout,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:"writeTimeout,omitempty" yaml:"writeTimeout,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:"idleTimeout,omitempty" yaml:"idleTimeout,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, http.DefaultMaxHeaderBytes is used.
	MaxHeaderBytes int `json:"maxHeaderBytes,omitempty" yaml:"maxHeaderBytes,omitempty"`
}

Directories

Path Synopsis
fx module

Jump to

Keyboard shortcuts

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