server

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2023 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsPrivateIP

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

func RealIP(r *http.Request) string

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

Types

type Option

type Option func(s *Server)

Option Server option

func WithAccessLog

func WithAccessLog(enabled bool) Option

WithAccessLog with server access log option

func WithAddr

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

func WithShutdownTimeout(timeout time.Duration) Option

WithShutdownTimeout with server shutdown timeout option

func WithStartupTimeout

func WithStartupTimeout(timeout time.Duration) Option

WithStartupTimeout with server startup timeout option

func WithStripQueryString

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
}

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

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

RunContext run server with context

type Service

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