server

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2020 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DefaultLogger

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

DefaultLogger default logger

func NewDefaultLogger

func NewDefaultLogger(args Fields) *DefaultLogger

NewDefaultLogger default logger

func (*DefaultLogger) Error

func (d *DefaultLogger) Error(args ...interface{})

Error error...

func (*DefaultLogger) Fatalln

func (d *DefaultLogger) Fatalln(args ...interface{})

Fatalln fatalln

func (*DefaultLogger) Info

func (d *DefaultLogger) Info(args ...interface{})

Info info...

func (*DefaultLogger) Println

func (d *DefaultLogger) Println(args ...interface{})

Println println...

func (DefaultLogger) WithFields

func (d DefaultLogger) WithFields(fields Fields) ILogger

WithFields Set other information to be recorded in the log, and a new object will be returned

type Fields

type Fields map[string]interface{}

Fields other info

type HTTPServer

type HTTPServer struct {
	PID                  string `mapstructure:"pid"`
	ServiceName          string `mapstructure:"name"`
	Addr                 string `mapstructure:"addr"`
	ShutdownWaitDuration string `mapstructure:"shutdown_wait_duration"`
	GinMode              string `mapstructure:"gin_mode"`
	// contains filtered or unexported fields
}

HTTPServer default http server

func NewHTTPServer

func NewHTTPServer(logger ILogger) *HTTPServer

NewHTTPServer simply initialize the HTTP server

func (*HTTPServer) GINLogger

func (httpServer *HTTPServer) GINLogger(ctx *gin.Context)

GINLogger 自定义的GIN日志处理中间件

func (*HTTPServer) GINRecovery

func (httpServer *HTTPServer) GINRecovery(ctx *gin.Context)

GINRecovery gin recovery handler

func (*HTTPServer) Handler

func (httpServer *HTTPServer) Handler(handler func(router *gin.Engine))

Handler use this method to register the handler of gin

func (*HTTPServer) Name

func (httpServer *HTTPServer) Name() string

Name get service name

func (*HTTPServer) OnChange

func (httpServer *HTTPServer) OnChange(viper *viper.Viper)

OnChange When the configuration file changes, the service will be listened again

func (*HTTPServer) PidSavePath

func (httpServer *HTTPServer) PidSavePath() string

PidSavePath get pid save path

func (*HTTPServer) Restart

func (httpServer *HTTPServer) Restart() error

Restart daemon restart

func (*HTTPServer) Run

func (httpServer *HTTPServer) Run()

Run start server listen, In fact, it is directly called globally daemon.Run() is an effect

func (*HTTPServer) SetLogger

func (httpServer *HTTPServer) SetLogger(logger ILogger)

SetLogger set custom logger

func (*HTTPServer) Start

func (httpServer *HTTPServer) Start()

Start daemon start handle

func (*HTTPServer) Stop

func (httpServer *HTTPServer) Stop() error

Stop daemon stop handler

type Handler

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

Handler router

func NewHandler

func NewHandler(mode string, recovery, ginLogger gin.HandlerFunc) *Handler

NewHandler init handler

func (*Handler) Group

func (*Handler) Group(relativePath string, handlers ...func(router gin.IRouter)) func(router gin.IRouter)

Group router group

func (*Handler) Print

func (handler *Handler) Print(l ILogger)

Print print route info

func (*Handler) Register

func (handler *Handler) Register(handlers ...func(router *gin.Engine))

Register register handler

func (*Handler) Router

func (handler *Handler) Router() *gin.Engine

Router get *gin.Engine

type ILogger

type ILogger interface {
	Println(args ...interface{})
	Error(args ...interface{})
	Info(args ...interface{})
	Fatalln(args ...interface{})
	WithFields(fields Fields) ILogger
}

ILogger methods to be implemented for loggers injected into HTTPServer

type Prometheus

type Prometheus struct{}

Prometheus 服务指标统计

var (
	// Metrics 指标统计
	Metrics Prometheus
)

func (Prometheus) HTTPRequestURICounter

func (Prometheus) HTTPRequestURICounter(uri string)

HTTPRequestURICounter http 请求资源计数

func (Prometheus) HTTPResponseStatusCounter

func (Prometheus) HTTPResponseStatusCounter(uri string, status int)

HTTPResponseStatusCounter http 响应状态码统计

func (Prometheus) RequestPanicCounter

func (Prometheus) RequestPanicCounter(uri string)

RequestPanicCounter http 发生崩溃的统计

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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