server

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2022 License: Apache-2.0 Imports: 14 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 Option

type Option func(s *Server)

func WithAccessLog added in v0.2.11

func WithAccessLog(enabled bool) Option

func WithAddr added in v0.5.9

func WithAddr(addr string) Option

func WithAddress

func WithAddress(address string) Option

func WithCORS

func WithCORS(enabled bool) Option

func WithDebug

func WithDebug(debug bool) Option

func WithLogger

func WithLogger(logger *zap.Logger) Option

func WithMiddleware

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

func WithPathPrefix

func WithPathPrefix(prefix string) Option

func WithPort

func WithPort(port int) Option

func WithShutdownTimeout added in v0.1.5

func WithShutdownTimeout(timeout time.Duration) Option

func WithStartupTimeout added in v0.1.5

func WithStartupTimeout(timeout time.Duration) Option

func WithStripQueryString added in v0.2.1

func WithStripQueryString(enabled bool) 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()

func (*Server) RunContext added in v0.5.9

func (s *Server) RunContext(ctx context.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