-
Notifications
You must be signed in to change notification settings - Fork 178
/
Copy pathhttp_option.go
43 lines (36 loc) · 871 Bytes
/
http_option.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
package server
import (
"github.com/go-dev-frame/sponge/pkg/servicerd/registry"
)
// HTTPOption setting up http
type HTTPOption func(*httpOptions)
type httpOptions struct {
isProd bool
instance *registry.ServiceInstance
iRegistry registry.Registry
}
func defaultHTTPOptions() *httpOptions {
return &httpOptions{
isProd: false,
instance: nil,
iRegistry: nil,
}
}
func (o *httpOptions) apply(opts ...HTTPOption) {
for _, opt := range opts {
opt(o)
}
}
// WithHTTPIsProd setting up production environment markers
func WithHTTPIsProd(isProd bool) HTTPOption {
return func(o *httpOptions) {
o.isProd = isProd
}
}
// WithHTTPRegistry registration services
func WithHTTPRegistry(iRegistry registry.Registry, instance *registry.ServiceInstance) HTTPOption {
return func(o *httpOptions) {
o.iRegistry = iRegistry
o.instance = instance
}
}