-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.go
76 lines (65 loc) · 1.48 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
package stargo
import (
"github.com/starfork/stargo/config"
"google.golang.org/grpc"
)
// Options 参数
type Options struct {
Org, Name, Addr string
Config *config.Config
UnaryInterceptor []grpc.UnaryServerInterceptor
StreamInterceptor []grpc.StreamServerInterceptor
Server []grpc.ServerOption
//Registry naming.Registry
//Tracer tracer.Tracer
//Logger logger.Logger
//Cache cache.Cache
}
// Option Option
type Option func(o *Options)
func Org(c string) Option {
return func(o *Options) {
o.Org = c
}
}
func Name(c string) Option {
return func(o *Options) {
o.Name = c
}
}
func Addr(c string) Option {
return func(o *Options) {
o.Addr = c
}
}
func Config(c *config.Config) Option {
return func(o *Options) {
o.Config = c
}
}
// UnaryInterceptor Unary server interceptor
func UnaryInterceptor(opt grpc.UnaryServerInterceptor) Option {
return func(o *Options) {
o.UnaryInterceptor = append(o.UnaryInterceptor, opt)
}
}
// StreamInterceptor Stream server interceptor
func StreamnIterceptor(opt grpc.StreamServerInterceptor) Option {
return func(o *Options) {
o.StreamInterceptor = append(o.StreamInterceptor, opt)
}
}
// Server option
func Server(opt ...grpc.ServerOption) Option {
return func(o *Options) {
o.Server = append(o.Server, opt...)
}
}
// DefaultOptions default options
func DefaultOptions() Options {
o := Options{
Org: "stargo", //与proto文件对称即可。比如stargo.service.ServiceHandler
Name: "service",
}
return o
}