1 Star 0 Fork 0

天雨流芳 / go-micro-framework

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
options.go 1.79 KB
AI 代码解读
一键复制 编辑 原始数据 按行查看 历史
package restserver
import (
"github.com/gin-gonic/gin"
socketio "github.com/googollee/go-socket.io"
)
type ServerOption func(*Server)
func WithEnableProfiling(enable bool) ServerOption {
return func(s *Server) {
s.enableProfiling = enable
}
}
func WithDebugMode() ServerOption {
return func(s *Server) {
s.mode = gin.DebugMode
}
}
func WithReleaseMode() ServerOption {
return func(s *Server) {
s.mode = gin.ReleaseMode
}
}
func WithTestMode() ServerOption {
return func(s *Server) {
s.mode = gin.TestMode
}
}
func WithAddress(addr string) ServerOption {
return func(s *Server) {
s.address = addr
}
}
func WithMiddlewares(middlewares ...gin.HandlerFunc) ServerOption {
return func(s *Server) {
s.middlewares = middlewares
}
}
// WithTLSConfig with TLS config.
func WithTLSConfig(certFile, keyFile string) ServerOption {
return func(o *Server) {
o.enableTls = true
o.certFile = certFile
o.keyFile = keyFile
}
}
func WithZhTransNames() ServerOption {
return func(s *Server) {
s.transName = "zh"
}
}
func WithEnTransNames() ServerOption {
return func(s *Server) {
s.transName = "en"
}
}
func WithSocketIoServer(socketIoServer *socketio.Server) ServerOption {
return func(s *Server) {
s.socketIoServer = socketIoServer
}
}
func WithEnableSocketIoServer(enableSocketIoServer bool) ServerOption {
return func(s *Server) {
s.enableSocketIoServer = enableSocketIoServer
}
}
// WithClientEnableTracing 设置是否开启链路追踪
func WithClientEnableTracing(enableTracing bool) ServerOption {
return func(s *Server) {
s.enableTracing = enableTracing
}
}
func WithTransName(transName string) ServerOption {
return func(s *Server) {
s.transName = transName
}
}
func WithEnableMetrics(enable bool) ServerOption {
return func(s *Server) {
s.enableMetrics = enable
}
}
1
https://gitee.com/tylf2018/go-micro-framework.git
git@gitee.com:tylf2018/go-micro-framework.git
tylf2018
go-micro-framework
go-micro-framework
4cc90ded505a

搜索帮助