server

package
v1.4.11 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2024 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsPrivateIP added in v0.2.11

func IsPrivateIP(address string) (bool, error)

IsPrivateIP works by checking if the address is under private CIDR blocks. List of private CIDR blocks can be seen on :

https://en.wikipedia.org/wiki/Private_network

https://en.wikipedia.org/wiki/Link-local_address

func RealIP added in v0.2.11

func RealIP(r *http.Request) string

RealIP return client's real public IP address from http request headers.

Types

type Metrics added in v1.4.0

type Metrics interface {

	// Handle HTTP middleware metrics handler
	Handle(next http.Handler) http.Handler

	// Startup controls metrics startup
	Startup(ctx context.Context) error

	// Shutdown controls metrics shutdown
	Shutdown(ctx context.Context) error
}

Metrics represents metrics Startup and Shutdown lifecycle and Handle middleware

type Option

type Option func(s *Server)

Option Server option

func WithAccessLog added in v0.2.11

func WithAccessLog(enabled bool) Option

WithAccessLog with server access log option

func WithAddr added in v0.5.9

func WithAddr(addr string) Option

WithAddr with server address with port option

func WithAddress

func WithAddress(address string) Option

WithAddress with server address option

func WithCORS

func WithCORS(enabled bool) Option

WithCORS with CORS option

func WithDebug

func WithDebug(debug bool) Option

WithDebug with debug option

func WithLogger

func WithLogger(logger *zap.Logger) Option

WithLogger with logger option

func WithMetrics added in v1.4.0

func WithMetrics(metrics Metrics) Option

WithMetrics with server metrics option

func WithMiddleware

func WithMiddleware(middleware func(http.Handler) http.Handler) Option

WithMiddleware with HTTP middleware option

func WithPathPrefix

func WithPathPrefix(prefix string) Option

WithPathPrefix with path prefix option

func WithPort

func WithPort(port int) Option

WithPort with port option

func WithShutdownTimeout added in v0.1.5

func WithShutdownTimeout(timeout time.Duration) Option

WithShutdownTimeout with server shutdown timeout option

func WithStartupTimeout added in v0.1.5

func WithStartupTimeout(timeout time.Duration) Option

WithStartupTimeout with server startup timeout option

func WithStripQueryString added in v0.2.1

func WithStripQueryString(enabled bool) Option

WithStripQueryString with strip query string option

type Server

type Server struct {
	http.Server
	App             Service
	Address         string
	Port            int
	CertFile        string
	KeyFile         string
	PathPrefix      string
	StartupTimeout  time.Duration
	ShutdownTimeout time.Duration
	Logger          *zap.Logger
	Debug           bool
	Metrics         Metrics
}

Server wraps the Service with additional http and app lifecycle handling

func New

func New(app Service, options ...Option) *Server

New create new Server

func (*Server) Run

func (s *Server) Run()

Run server that terminates on SIGINT, SIGTERM signals

func (*Server) RunContext added in v0.5.9

func (s *Server) RunContext(ctx context.Context)

RunContext run server with context

type Service added in v0.2.1

type Service interface {
	http.Handler

	// Startup controls app startup
	Startup(ctx context.Context) error

	// Shutdown controls app shutdown
	Shutdown(ctx context.Context) error
}

Service is a http.Handler with Startup and Shutdown lifecycle

Jump to

Keyboard shortcuts

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