-
Notifications
You must be signed in to change notification settings - Fork 12
/
gateway_options.go
80 lines (66 loc) · 1.84 KB
/
gateway_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
78
79
80
// Code generated by "go-option -type=Gateway"; DO NOT EDIT.
// Install go-option by "go get install github.com/searKing/golang/tools/go-option"
package grpc
import (
"net/http"
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
"google.golang.org/grpc"
)
// A GatewayOption sets options.
type GatewayOption interface {
apply(*Gateway)
}
// EmptyGatewayOption does not alter the configuration. It can be embedded
// in another structure to build custom options.
//
// This API is EXPERIMENTAL.
type EmptyGatewayOption struct{}
func (EmptyGatewayOption) apply(*Gateway) {}
// GatewayOptionFunc wraps a function that modifies Gateway into an
// implementation of the GatewayOption interface.
type GatewayOptionFunc func(*Gateway)
func (f GatewayOptionFunc) apply(do *Gateway) {
f(do)
}
// ApplyOptions call apply() for all options one by one
func (o *Gateway) ApplyOptions(options ...GatewayOption) *Gateway {
for _, opt := range options {
if opt == nil {
continue
}
opt.apply(o)
}
return o
}
// WithGateway sets Gateway.
func WithGateway(v Gateway) GatewayOption {
return GatewayOptionFunc(func(o *Gateway) {
*o = v
})
}
// WithGatewayOpt sets opt in Gateway.
// options
func WithGatewayOpt(v gatewayOption) GatewayOption {
return GatewayOptionFunc(func(o *Gateway) {
o.opt = v
})
}
// WithGatewayHttpMuxToGrpc sets httpMuxToGrpc in Gateway.
func WithGatewayHttpMuxToGrpc(v *runtime.ServeMux) GatewayOption {
return GatewayOptionFunc(func(o *Gateway) {
o.httpMuxToGrpc = v
})
}
// WithGatewayHandler sets Handler in Gateway.
func WithGatewayHandler(v http.Handler) GatewayOption {
return GatewayOptionFunc(func(o *Gateway) {
o.Handler = v
})
}
// WithGatewayGrpcServer sets grpcServer in Gateway.
// runtime
func WithGatewayGrpcServer(v *grpc.Server) GatewayOption {
return GatewayOptionFunc(func(o *Gateway) {
o.grpcServer = v
})
}