httpext

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2021 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const HeaderContentType = "Content-type"

HeaderContentType denotes the header key to be used to send the content type

View Source
const HeaderTraceID = "X-Trace-Id"

Variables

View Source
var HealthzResponse = []byte("he's not dead, jim")

HealthzResponse is the response to be returned when requesting the health of the server

Functions

func AddCommandLineFlags

func AddCommandLineFlags(result *Config)

AddCommandLineFlags adds all flags to flag.CommandLine for parsing the provided Config, using it's values as default

func AddFlagsToFlagSet

func AddFlagsToFlagSet(result *Config, flagSet *flag.FlagSet)

AddFlagsToFlagSet works like AddCommandLineFlags but let's you specify the target flag.FlagSet

func CreateTLSConfig

func CreateTLSConfig(config TLSConfig) (*tls.Config, error)

CreateTLSConfig creates a tls.Config from our TLSConfig

Types

type Config

type Config struct {
	// ServerNamespace is a name for the server to be used as namespace for the prometheus Metrics
	ServerNamespace string
	// Addr is the address to listen to
	Addr string
	// TLSConfig denotes the TLSConfig to be used
	TLSConfig TLSConfig
	// ReadTimeout denotes the timeout for reading the complete request
	ReadTimeout time.Duration
	// ReadHeaderTimeout denotes the timeout for reading the headers
	ReadHeaderTimeout time.Duration
	// WriteTimeout denotes the timeout for writing the complete response
	WriteTimeout time.Duration
	// IdleTimeout denotes the timeout for an idling request
	IdleTimeout time.Duration
	// MaxHeaderBytes denotes the maximum acceptable size of the request header in bytes
	MaxHeaderBytes int
}

Config denotes the configuration parameters for Server

func NewDefaultConfig

func NewDefaultConfig() Config

NewDefaultConfig returns a new Config with the default options set

type Handler

type Handler func(writer ResponseWriter, request *Request)

Handler is a function which handles the decorated ResponseWriter and Request

type Metrics

type Metrics interface {
	// Requests provides the metering.Summary for the http requests
	Requests() metering.Summary
}

Metrics provides access the http metrics

type MetricsRegistry

type MetricsRegistry interface {
	metering.MetricsRegistry
	// HTTP provides the Metrics for the http subsystem
	HTTP() Metrics
}

MetricsRegistry extends metering.MetricsRegistry for accessing HTTP metrics

type Request

type Request struct {
	*http.Request
	// contains filtered or unexported fields
}

Request is a decorator for http.Request

func (*Request) Logger

func (d *Request) Logger() logr.Logger

Logger returns the logger for the request

func (*Request) ReadBody

func (d *Request) ReadBody() ([]byte, error)

ReadBody will read the whole body, close it and return the contents

func (*Request) ReadBodyAsJSON

func (d *Request) ReadBodyAsJSON(obj interface{}) error

ReadBodyAsJSON will try to read the body as JSON into the provided object

type ResponseWriter

type ResponseWriter interface {
	http.ResponseWriter
	// SendResponse sends a response with status code handling internal errors
	SendResponse(statusCode int, body []byte)
	// SendResponseString sends a string response
	SendResponseString(statusCode int, body string)
	// SendJSON marshals the provided object to JSON
	SendJSON(statusCode int, obj interface{})
	// SendJSONBytes sends a marshaled json object
	SendJSONBytes(statusCode int, body []byte)
	// HandleInternalError will handle error occurred sending http.StatusInternalServerError, also logging the error
	HandleInternalError(err error)
	// Status yields the sent status response
	Status() int
}

ResponseWriter is a decorator for http.ResponseWriter

type Server

type Server struct {
	*http.Server
	*http.ServeMux

	Metrics MetricsRegistry
	// contains filtered or unexported fields
}

Server is an extended http.Server

func NewServer

func NewServer(logger logr.Logger, config *Config) (*Server, error)

NewServer creates a server from a logr.Logger and a Config

func (*Server) HandleExt

func (s *Server) HandleExt(path string, handler Handler)

HandleExt adds a Handler for the provided path

func (*Server) RunWaitingForSig

func (s *Server) RunWaitingForSig(signals ...os.Signal) chan error

RunWaitingForSig runs the server waiting for one of the provided os.Signal

type TLSConfig

type TLSConfig struct {
	// MinVersion is the minimum version string (e.g. 1.2)
	MinVersion string
	// CaCertsFile is the path to the CA certificates file to be used
	CaCertsFile string
	// PrivateKeyFile is the key file for the private key
	PrivateKeyFile string
	// PublicKeyFile is the key file for the public key
	PublicKeyFile string
}

TLSConfig denotes the TLS configuration for Server

Jump to

Keyboard shortcuts

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