-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.go
98 lines (80 loc) · 1.79 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
package app
import (
"context"
"net/url"
"os"
"time"
"github.com/gole-dev/gole/pkg/registry"
"github.com/gole-dev/gole/pkg/log"
"github.com/gole-dev/gole/pkg/transport"
)
// Option is func for application
type Option func(o *options)
// options is an application options
type options struct {
id string
name string
version string
metadata map[string]string
endpoints []*url.URL
sigs []os.Signal
ctx context.Context
logger log.Logger
registry registry.Registry
registryTimeout time.Duration
servers []transport.Server
}
// WithID with app id
func WithID(id string) Option {
return func(o *options) {
o.id = id
}
}
// WithName .
func WithName(name string) Option {
return func(o *options) {
o.name = name
}
}
// WithVersion with a version
func WithVersion(version string) Option {
return func(o *options) {
o.version = version
}
}
// WithContext with a context
func WithContext(ctx context.Context) Option {
return func(o *options) {
o.ctx = ctx
}
}
// WithSignal with some system signal
func WithSignal(sigs ...os.Signal) Option {
return func(o *options) {
o.sigs = sigs
}
}
// WithMetadata with service metadata.
func WithMetadata(md map[string]string) Option {
return func(o *options) { o.metadata = md }
}
// WithEndpoint with service endpoint.
func WithEndpoint(endpoints ...*url.URL) Option {
return func(o *options) { o.endpoints = endpoints }
}
// WithRegistry with service registry.
func WithRegistry(r registry.Registry) Option {
return func(o *options) { o.registry = r }
}
// WithLogger .
func WithLogger(logger log.Logger) Option {
return func(o *options) {
o.logger = logger
}
}
// WithServer with a server , http or grpc
func WithServer(srv ...transport.Server) Option {
return func(o *options) {
o.servers = srv
}
}