httpserver

package
v0.4.5 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2025 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InitListener

func InitListener(cfg Config) (net.Listener, error)

InitListener preloads certificates and returns a configured net.Listener

Types

type CertificateGetter

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

CertificateGetter allows to load certificates. The GetCertificate method satisfies the tls.GetCertificate function signature.

func NewCertificateGetter

func NewCertificateGetter(certFile, keyFile string) *CertificateGetter

func (*CertificateGetter) GetCertificate

func (cg *CertificateGetter) GetCertificate(_ *tls.ClientHelloInfo) (*tls.Certificate, error)

func (*CertificateGetter) Load

func (cg *CertificateGetter) Load() error

type Config

type Config struct {
	Port             int            `yaml:"port" description:"Port number API listens on" default:"8080"`
	StatsPort        int            `yaml:"stats_port" description:"Port number stats server listens on" default:"8081"`
	UseTLS           bool           `yaml:"use_tls" description:"Use TLS for API calls"`
	TLSCert          string         `yaml:"tls_cert" description:"API TLS cert location"`
	TLSKey           string         `yaml:"tls_key" description:"API TLS key location"`
	TLSCA            string         `yaml:"tls_ca" description:"Optional CA certificate"` //nolint:tagliatelle
	TLSUseClientCert bool           `yaml:"tls_use_client_cert" description:"Require and verify client certificate"`
	TLSClientCA      string         `yaml:"tls_client_ca" description:"Certificate Authority file for checking the authenticity of client"`
	CORS             bool           `yaml:"cors" description:"Allow CORS"`
	Token            string         `yaml:"token" description:"Secret auth token"`
	RateLimit        rate.Limit     `yaml:"rate_limit" description:"Rate limit (RPS)" default:"10000"`
	OpenConnLimit    int            `yaml:"open_conn_limit" description:"Open incoming connection limit" default:"1000"`
	ReadTimeout      time.Duration  `yaml:"read_timeout" description:"Server read timeout (closes idle keep-alive connection)" default:"5m"`
	ShutdownTimeout  time.Duration  `yaml:"shutdown_timeout" description:"Server shutdown timeout" default:"2s"`
	Metrics          metrics.Config `yaml:"metrics" description:"Server metrics configuration"`
}

Config defines server parameters

func (*Config) CertFile

func (t *Config) CertFile() (string, error)

CertFile returns filename of TLS certificate containing the server certificate alone or (for CA-based key) both CA certificate and server certificate.

type ConnectionWatcher

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

func NewConnectionWatcher

func NewConnectionWatcher(metricsRegistry prometheus.Registerer, logger log.MetaLogger) *ConnectionWatcher

func (*ConnectionWatcher) Count

func (cw *ConnectionWatcher) Count() int64

Count returns the current number of open connections

func (*ConnectionWatcher) OnStateChange

func (cw *ConnectionWatcher) OnStateChange(conn net.Conn, state http.ConnState)

OnStateChange records open connections in response to connection state changes

type ContextKey

type ContextKey string
const ContextRequestID ContextKey = "requestID"

type HandlerWithResult

type HandlerWithResult func(w http.ResponseWriter, r *http.Request) (int, error)

HandlerWithResult is an HTTP handler that returns status code and error

type ListenerConfig

type ListenerConfig struct {
	Address          string
	TLSEnabled       bool
	TLSCertFile      string
	TLSKeyFile       string
	TLSUseClientCert bool
	TLSClientCAFile  string
}

type Router

type Router interface {
	ServeHTTP(w http.ResponseWriter, r *http.Request)
	// Handle(pattern string, handler http.Handler)
	HandleFunc(method, pattern string, handler func(http.ResponseWriter, *http.Request))
}

Router implements a basic router interface. Currently in this repo you can find a gorilla/mux router wrapper and a standard ServeMux router wrapper. You can create a wrapper for your favourite router/multiplexer and pass it as Router to a NewServer() func.

type Server

type Server interface {
	Run(ctx context.Context) error
	HandleFunc(service, endpoint, method, path string, handler HandlerWithResult)
}

Server implements basic Kube-dispatched HTTP server

func NewServer

func NewServer(
	cfg Config,
	cfgMetrics metrics.Config,
	router Router,
	logger log.MetaLogger,
	metricsRegistry *metrics.Registry,
	sentryHandler *sentryhttp.Handler,
) (Server, error)

NewServer returns an HTTP server

type UnknownCNBehavior

type UnknownCNBehavior string
const (
	UCNAllow UnknownCNBehavior = "allow"
	UCNWarn  UnknownCNBehavior = "warn"
	UCNBlock UnknownCNBehavior = "block"
)

Jump to

Keyboard shortcuts

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