server

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: May 19, 2021 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Code in this file is adapted directly from the Gin library (https://github.com/gin-gonic/gin) to overcome its limitations in resolving source IP addresses from headers

Index

Constants

This section is empty.

Variables

View Source
var DisableAccessLog = func(config *serverConfig) {
	config.disableAccessLog = true
}
View Source
var DisableHealthCheck = func(debugAPI *DebugAPI) {
	debugAPI.enableHealthCheck = false
}
View Source
var DisableMethodNotAllowedHandler = func(config *serverConfig) {
	config.disableMethodNotAllowedHandler = true
}
View Source
var DisableMetrics = func(debugAPI *DebugAPI) {
	debugAPI.enableMetrics = false
}
View Source
var DisableNotFoundHandler = func(config *serverConfig) {
	config.disableNotFoundHandler = true
}
View Source
var DisablePprof = func(debugAPI *DebugAPI) {
	debugAPI.enablePprof = false
}
View Source
var DisableRecovery = func(config *serverConfig) {
	config.disableRecovery = true
}

Functions

func AccessLogSkipPath

func AccessLogSkipPath(paths []string) serverOpt

func Address

func Address(address string) serverOpt

func AppName

func AppName(appName string) debugAPIOpt

func AppVersion

func AppVersion(appVersion string) debugAPIOpt

func ApplyDebugAPIProperties

func ApplyDebugAPIProperties(properties *DebugAPIProperties) debugAPIOpt

func ApplyProperties

func ApplyProperties(properties *Properties) serverOpt

func GetRealClientIP added in v1.0.3

func GetRealClientIP(c *gin.Context) string

func HealthCheckHandler

func HealthCheckHandler(handler HealthCheckHandlerFunc) debugAPIOpt

func HealthCheckPath added in v1.0.3

func HealthCheckPath(path string) debugAPIOpt

func MetricsPath added in v1.0.3

func MetricsPath(path string) debugAPIOpt

func OnShutdown

func OnShutdown(callback func()) serverOpt

func OnSignal added in v1.0.3

func OnSignal(callback func(os.Signal), signals ...os.Signal) serverOpt

func PprofPath added in v1.0.3

func PprofPath(path string) debugAPIOpt

func ShutdownSignals added in v1.0.3

func ShutdownSignals(signals ...os.Signal) serverOpt

func ShutdownTimeout

func ShutdownTimeout(timeout time.Duration) serverOpt

func TrustedProxies added in v1.0.3

func TrustedProxies(cidr ...string) serverOpt

Types

type AccessLogProperties added in v1.0.3

type AccessLogProperties struct {
	Disable          bool     `json:"disable" yaml:"disable"`
	SkipPaths        []string `json:"skipPaths" yaml:"skipPaths"`
	SuccessLevel     string   `json:"successLevel" yaml:"successLevel"`
	UserErrorLevel   string   `json:"userErrorLevel" yaml:"userErrorLevel"`
	ServerErrorLevel string   `json:"serverErrorLevel" yaml:"serverErrorLevel"`
}

type DebugAPI

type DebugAPI struct {
	// contains filtered or unexported fields
}

func NewDebugAPI

func NewDebugAPI(opts ...debugAPIOpt) *DebugAPI

func (*DebugAPI) Register

func (debugAPI *DebugAPI) Register(engine *gin.Engine)

type DebugAPIHealthcheckProperties added in v1.0.3

type DebugAPIHealthcheckProperties struct {
	Disable bool   `json:"disable" yaml:"disable"`
	Path    string `json:"path" yaml:"path"`
}

type DebugAPIMetricsProperties added in v1.0.3

type DebugAPIMetricsProperties struct {
	Disable bool   `json:"disable" yaml:"disable"`
	Path    string `json:"path" yaml:"path"`
}

type DebugAPIPprofProperties added in v1.0.3

type DebugAPIPprofProperties struct {
	Disable bool   `json:"disable" yaml:"disable"`
	Path    string `json:"path" yaml:"path"`
}

type DebugAPIProperties

type DebugAPIProperties struct {
	Metrics     *DebugAPIMetricsProperties     `json:"metrics" yaml:"metrics"`
	Pprof       *DebugAPIPprofProperties       `json:"pprof" yaml:"pprof"`
	Healthcheck *DebugAPIHealthcheckProperties `json:"healthcheck" yaml:"healthcheck"`
	AppName     string                         `json:"appName" yaml:"appName"`
	AppVersion  string                         `json:"appVersion" yaml:"appVersion"`
}

type Endpoint

type Endpoint interface {
	Register(*gin.Engine)
}

func CreateEndpoint

func CreateEndpoint(method, path string, handlers ...gin.HandlerFunc) Endpoint

type HealthCheckHandlerFunc

type HealthCheckHandlerFunc = func() bool

type Properties

type Properties struct {
	Address                        string               `json:"address" yaml:"address"`
	ShutdownTimeout                int64                `json:"shutdownTimeout" yaml:"shutdownTimeout"`
	ShutdownSignals                []string             `json:"shutdownSignals" yaml:"shutdownSignals"`
	DisableRecovery                bool                 `json:"disableRecovery" yaml:"disableRecovery"`
	DisableMethodNotAllowedHandler bool                 `json:"disableMethodNotAllowedHandler" yaml:"disableMethodNotAllowedHandler"`
	DisableNotFoundHandler         bool                 `json:"disableNotFoundHandler" yaml:"disableNotFoundHandler"`
	TrustedProxies                 []string             `json:"trustedProxies" yaml:"trustedProxies"`
	AccessLog                      *AccessLogProperties `json:"accessLog" yaml:"accessLog"`
}

type Server

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

func NewServer

func NewServer(opts ...serverOpt) *Server

func (*Server) RegisterEndpoints

func (server *Server) RegisterEndpoints(endpoints ...Endpoint)

func (*Server) StartAndBlock

func (server *Server) StartAndBlock()

Jump to

Keyboard shortcuts

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