server

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2022 License: Apache-2.0 Imports: 35 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AccessLogMiddleware

func AccessLogMiddleware(opt *AccessLogMwOptions) gin.HandlerFunc

func GetConfigPath

func GetConfigPath() string

func OutermostRecover

func OutermostRecover() gin.HandlerFunc

func SemicolonMiddleware

func SemicolonMiddleware() gin.HandlerFunc

func ServerRecover

func ServerRecover() gin.HandlerFunc

func SetConfigPath

func SetConfigPath(path string)

func TrafficStopMiddleware

func TrafficStopMiddleware() gin.HandlerFunc

Types

type AccessLogMwOptions

type AccessLogMwOptions struct {
	Enabled         bool
	Pattern         string
	Path            string
	FilePathPattern string // 定义文件路径名称格式
	NoFile          bool
	MaxAge          time.Duration // 默认7天
	RotationTime    time.Duration // 默认1天
	RotationSize    int64         // 单位MB,默认1024
}

func NewDefaultAccessLogOptions

func NewDefaultAccessLogOptions() *AccessLogMwOptions

type MiddlewaresOptions

type MiddlewaresOptions struct {
	AccessLog *AccessLogMwOptions
}

type Options

type Options struct {
	Port            int
	Mode            string
	ShutdownTimeout time.Duration
	Middlewares     *MiddlewaresOptions
}

func NewDefaultOptions

func NewDefaultOptions() *Options

type PprofOptions

type PprofOptions struct {
	Switch bool // 是否开启
	Port   int  // 配置端口号
}

PprofOptions 用于开启调试模式

type Server

type Server struct {
	*http.Server

	*gin.Engine

	PreStart func() error
	PreStop  func(context.Context) error
	// contains filtered or unexported fields
}

func Init

func Init() *Server

Init 初始化全局唯一server

func (*Server) AddRoute

func (s *Server) AddRoute(method Method, path string, handlers ...gin.HandlerFunc) *Server

func (*Server) AddRouteWithMethods

func (s *Server) AddRouteWithMethods(methods []Method, path string, handlers ...gin.HandlerFunc) *Server

func (*Server) GoAttach

func (s *Server) GoAttach(f func())

GoAttach 用指定func创建一个goroutine,并用waitgroup跟踪它 注意传递的函数必须在s.StoppingNotify()关闭后停止

func (*Server) Start

func (s *Server) Start()

func (*Server) Stop

func (s *Server) Stop(ctx context.Context) error

Stop 停止服务

func (*Server) StoppingNotify

func (s *Server) StoppingNotify() <-chan struct{}

StoppingNotify 返回一个channel,它会在server停止时被关闭

type ServiceOptions

type ServiceOptions struct {
	AppName     string
	ClusterName string
	Instance    string
}

ServiceOptions 整合了服务的全局配置

func (*ServiceOptions) Check

func (o *ServiceOptions) Check() error

Check 检查配置合法性

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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