-
Notifications
You must be signed in to change notification settings - Fork 2
/
options.go
77 lines (65 loc) · 1.77 KB
/
options.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package kratosx
import (
"github.com/go-kratos/kratos/v2"
kratosConfig "github.com/go-kratos/kratos/v2/config"
"github.com/go-kratos/kratos/v2/middleware"
"github.com/go-kratos/kratos/v2/transport/grpc"
"github.com/go-kratos/kratos/v2/transport/http"
"github.com/limes-cloud/kratosx/config"
"github.com/limes-cloud/kratosx/library/logger"
)
type Option func(o *options)
type RegistrarServerFn func(config config.Config, hs *http.Server, gs *grpc.Server)
type options struct {
regSrvFn RegistrarServerFn
loggerFields logger.LogField
config config.Config
kOpts []kratos.Option
httpSrvOptions []http.ServerOption
grpcSrvOptions []grpc.ServerOption
midOpts []middleware.Middleware
}
// RegistrarServer 服务注册
func RegistrarServer(fn RegistrarServerFn) Option {
return func(o *options) {
o.regSrvFn = fn
}
}
// LoggerWith 自定义字段
func LoggerWith(fields logger.LogField) Option {
// var fs []any
// for key, val := range fields {
// fs = append(fs, key, val)
// }
return func(o *options) { o.loggerFields = fields }
}
// Config 配置接入
func Config(source kratosConfig.Source) Option {
return func(o *options) {
o.config = config.New(source)
}
}
// Options kratos option
func Options(opts ...kratos.Option) Option {
return func(o *options) {
o.kOpts = opts
}
}
// HttpServerOptions http server option
func HttpServerOptions(opts ...http.ServerOption) Option {
return func(o *options) {
o.httpSrvOptions = opts
}
}
// GrpcServerOptions grpc server option
func GrpcServerOptions(opts ...grpc.ServerOption) Option {
return func(o *options) {
o.grpcSrvOptions = opts
}
}
// MiddlewareOptions middleware option
func MiddlewareOptions(opts ...middleware.Middleware) Option {
return func(o *options) {
o.midOpts = opts
}
}