httputil

package
v1.1.49 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2022 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Provides HTTP server implementation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Server

type Server struct {
	*gin.Engine
	// contains filtered or unexported fields
}

Server is an object representing gin.Engine and implementing the lifecycle.Service interface.

func NewServer

func NewServer(opts ...ServerOpt) *Server

NewServer creates new Server instance.

func (*Server) OnNoRoute added in v1.1.49

func (server *Server) OnNoRoute(handler func(c *gin.Context))

OnNoRoute sets a handler for requests that cannot be routed and would end up as 404s.

func (*Server) OnPanic added in v1.1.49

func (server *Server) OnPanic(handler func(c *gin.Context, recovered any))

OnPanic sets a handler for requests that resulted in panic and would end up as 500s.

func (*Server) Start

func (server *Server) Start() error

Start implements the interface of coreutil.Service.

func (*Server) Stop

func (server *Server) Stop()

Stop implements the interface of coreutil.Service.

type ServerConfig added in v1.1.49

type ServerConfig struct {
	// Address is an address to bind server socket to (default: "0.0.0.0:8080").
	Address string

	// SecurityHeaders defines whether to include HTTP security headers to all responses or not (default: true).
	SecurityHeaders bool

	// ShutdownTimeout defines a maximal timeout of HTTP server shutdown (default: 5s).
	ShutdownTimeout time.Duration
}

ServerConfig holds a configuration for NewServer.

type ServerOpt

type ServerOpt = func(*ServerConfig)

ServerOpt is an option to be specified to NewServer.

func Address

func Address(address string) ServerOpt

Address is an address to bind server socket to.

func SecurityHeaders

func SecurityHeaders(securityHeaders bool) ServerOpt

SecurityHeaders defines whether to include HTTP security headers to all responses or not.

func ShutdownTimeout

func ShutdownTimeout(timeout time.Duration) ServerOpt

ShutdownTimeout defines a maximal timeout of HTTP server shutdown.

Jump to

Keyboard shortcuts

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