-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.go
56 lines (45 loc) · 1.04 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
package g3server
import (
"net/http"
gwRuntime "github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
"google.golang.org/grpc"
)
type g3SOption struct {
grpcDialOptList []grpc.DialOption
gwServeMuxOptList []gwRuntime.ServeMuxOption
httpServer *http.Server
}
var defaultg3SOption = g3SOption{
grpcDialOptList: nil,
gwServeMuxOptList: nil,
httpServer: nil,
}
type Option interface {
apply(*g3SOption)
}
type funcG3SOption struct {
f func(*g3SOption)
}
func (fdo *funcG3SOption) apply(do *g3SOption) {
fdo.f(do)
}
func newG3SFuncOption(f func(*g3SOption)) *funcG3SOption {
return &funcG3SOption{
f: f,
}
}
func WithGRPCDialOption(optList []grpc.DialOption) Option {
return newG3SFuncOption(func(o *g3SOption) {
o.grpcDialOptList = optList
})
}
func WithGWServeMuxOption(optList []gwRuntime.ServeMuxOption) Option {
return newG3SFuncOption(func(o *g3SOption) {
o.gwServeMuxOptList = optList
})
}
func WithHTTPServerOption(s *http.Server) Option {
return newG3SFuncOption(func(o *g3SOption) {
o.httpServer = s
})
}