server

package
v1.5.5 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2023 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	InvalidGrpcServer = errors.New("invalid grpc server")
	InvalidGrpcConf   = errors.New("invalid grpc config")
)
View Source
var (
	InvalidHttpConf   = errors.New("invalid http config")
	InvalidHttpEngine = errors.New("invalid http engine")
)

Functions

func GraceGrpcServer added in v1.2.2

func GraceGrpcServer(graceGrpc *GraceGrpc) error

GraceGrpcServer 优雅启动grpc服务.

func GraceHttpServer added in v1.2.2

func GraceHttpServer(graceHttp *GraceHttp) error

Types

type GraceGrpc added in v1.3.2

type GraceGrpc struct {
	// Addr grpc地址, eg: ":7777"
	Addr   string
	Server *grpc.Server
	// RegisterReflect 启动grpc反射
	RegisterReflect bool
	// EnableGateway 启动grpc gateway
	EnableGateway bool
	// GatewayAddr gateway的地址
	GatewayAddr string
	// HttpHandlers http处理器
	HttpHandlers []HttpHandler
	// GatewayWaitTime gateway关闭时, 处理gateway请求时间
	GatewayWaitTime time.Duration
	// OnHookFunc 勾子函数
	OnHookFunc
}

GraceGrpc grpc启动配置.

type GraceHttp added in v1.3.2

type GraceHttp struct {
	Engine http.Handler
	// Addr 地址
	Addr string `json:"addr" yaml:"addr"`
	// WaitSecond 等待时间
	WaitSecond int `json:"waitTime" yaml:"waitTime"`
	// OnHookFunc 勾子函数
	OnHookFunc

	GraceGrpc *GraceGrpc
}

type HookHandler added in v1.2.2

type HookHandler func() error

type HttpHandler added in v1.3.2

type HttpHandler func(context.Context, *runtime.ServeMux, string, []grpc.DialOption) error

type OnHookFunc added in v1.2.2

type OnHookFunc struct {
	// StartUp 服务启动前执行函数
	StartUp []HookHandler
	// ShutDown 停止服务执行函数
	ShutDown []HookHandler
}

OnHookFunc 勾子结构体.

func (OnHookFunc) ExecuteShutDown added in v1.3.2

func (h OnHookFunc) ExecuteShutDown() error

ExecuteShutDown 执行结束后操作.

func (OnHookFunc) ExecuteStartUp added in v1.3.2

func (h OnHookFunc) ExecuteStartUp() error

ExecuteStartUp 执行启动前操作.

type Setting added in v1.3.2

type Setting struct {
	Host            string            `json:"host" yaml:"host"`                       // 地址
	Port            int               `json:"port" yaml:"port"`                       // 端口, 默认是9000
	Language        string            `json:"language" yaml:"language"`               // 校验错误返回的语言
	ShutDownTimeout int               `json:"shutDownTimeout" yaml:"shutDownTimeout"` // 优雅重启, 接收到相关信号后, 处理请求的最长时间, 单位: 秒, 默认3s
	Application     string            `json:"application" yaml:"application"`         // 应用名
	Debug           bool              `json:"debug" yaml:"debug"`                     // debug, 默认false
	Swagger         bool              `json:"swagger" yaml:"swagger"`                 // 是否启动swagger, 默认false
	LogConfig       log.ZapLogReq     `json:"log" yaml:"log"`                         // 日志配置
	EnableRtPool    bool              `json:"enableRtPool" yaml:"enableRtPool"`       // 启用协程池, 默认是false
	Routine         routine.Routine   `json:"routine" yaml:"routine"`                 // 协程池配置
	Middlewares     []gin.HandlerFunc // 中间件
	OnHookFunc                        // server勾子函数
	GrpcConf        *GraceGrpc        // grpc配置
}

func (*Setting) Arrange added in v1.3.2

func (s *Setting) Arrange()

Arrange 处理零值及无效字段为默认值.

Jump to

Keyboard shortcuts

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