-
Notifications
You must be signed in to change notification settings - Fork 3
/
options.go
111 lines (95 loc) · 2.21 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package edge
import (
"context"
"time"
nedge "github.com/micro-community/x-edge/edge"
"github.com/micro/cli/v2"
"github.com/micro/go-micro/v2"
"github.com/micro/go-micro/v2/auth"
"github.com/micro/go-micro/v2/registry"
"github.com/micro/go-micro/v2/transport"
)
//Options of edge app
type Options struct {
//Global Metadata
Namespace string
Name string
Version string
ID string
Metadata map[string]string
Address string
Advertise string
Action func(*cli.Context)
Flags []cli.Flag
RegisterTTL time.Duration
RegisterInterval time.Duration
// RegisterCheck runs a check function before registering the service
RegisterCheck func(context.Context) error
Registry registry.Registry
//two service end
MicroService micro.Service
Edge nedge.Service
//for edge server
EdgeTransport transport.Transport
EdgeHost string
Extractor nedge.PackageExtractor
// auth service
auth auth.Auth
// Alternative Options
Context context.Context
}
//Option of edge app
type Option func(*Options)
func newOptions(opts ...Option) Options {
opt := Options{
MicroService: micro.NewService(),
Edge: nedge.NewServer(),
Context: context.TODO(),
}
for _, o := range opts {
o(&opt)
}
return opt
}
// MicroService sets the micro.Service for internal communication
func MicroService(s micro.Service) Option {
return func(o *Options) {
o.MicroService = s
}
}
// MicroEdge sets the edge.Service for end/controller/gw communication
func MicroEdge(e nedge.Service) Option {
return func(o *Options) {
o.Edge = e
}
}
//Namespace of edge server
func Namespace(n string) Option {
return func(o *Options) {
o.Namespace = n
}
}
// Version of the service
func Version(v string) Option {
return func(o *Options) {
o.Version = v
}
}
// Action of the service
func Action(a func(*cli.Context)) Option {
return func(o *Options) {
o.Action = a
}
}
// EgTransport of the edge
func EgTransport(et transport.Transport) Option {
return func(o *Options) {
o.EdgeTransport = et
}
}
// EgExtractor of the edge
func EgExtractor(ext nedge.PackageExtractor) Option {
return func(o *Options) {
o.Extractor = ext
}
}