-
Notifications
You must be signed in to change notification settings - Fork 1
/
options.go
161 lines (149 loc) · 3.13 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
package otfalign
import (
"github.com/nsip/otf-align/internal/util"
)
type Option func(*OtfAlignService) error
//
// apply all supplied options to the service
// returns any error encountered while applying the options
//
func (srvc *OtfAlignService) setOptions(options ...Option) error {
for _, opt := range options {
if err := opt(srvc); err != nil {
return err
}
}
return nil
}
//
// set the name of this instance of the service
// used for audit tracing purposes if multiple
// instances of the service are active.
// If no name provided a hashid-style unique
// short name will be generated
//
func Name(name string) Option {
return func(s *OtfAlignService) error {
if name != "" {
s.serviceName = name
return nil
}
s.serviceName = util.GenerateName()
return nil
}
}
//
// create a unique id for this service instance, if none
// provided a nuid will be generated by default
//
func ID(id string) Option {
return func(s *OtfAlignService) error {
if id != "" {
s.serviceID = id
return nil
}
s.serviceID = util.GenerateID()
return nil
}
}
//
// set the hostname/address of this service
//
func Host(hname string) Option {
return func(s *OtfAlignService) error {
if hname != "" {
s.serviceHost = hname
return nil
}
s.serviceHost = "localhost"
return nil
}
}
//
// set the port to run this ersvice on.
// if 0 then acquire avaialble port from OS
//
func Port(port int) Option {
return func(s *OtfAlignService) error {
if port != 0 {
s.servicePort = port
return nil
}
osPort, err := util.AvailablePort()
if err != nil {
return err
}
s.servicePort = osPort
return nil
}
}
//
// set the hostname/address of the nias3 web server
// defaults to loacalhost if no host given
//
func NiasHost(hname string) Option {
return func(s *OtfAlignService) error {
if hname != "" {
s.niasHost = hname
return nil
}
s.niasHost = "localhost"
return nil
}
}
//
// set the port of the nias3 web server
// defaults to 1323 (n3w defalt port)
//
func NiasPort(port int) Option {
return func(s *OtfAlignService) error {
if port != 0 {
s.niasPort = port
return nil
}
s.niasPort = 1323
return nil
}
}
//
// set the access token of the nias3 web server
// defaults to demo otf token if not given
//
func NiasToken(tkn string) Option {
return func(s *OtfAlignService) error {
if tkn != "" {
s.niasToken = tkn
return nil
}
s.niasToken = "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJkZW1vIiwiY25hbWUiOiJhbGlnbm1lbnRNYXBzIiwidW5hbWUiOiJuc2lwT3RmIn0.Hxepr1xqGpUC6amoO8eTlszM-M2sakLhtwBYHSi-Cig"
return nil
}
}
//
// set the hostname/address of the text classifier (otf-classifier) web service
// defaults to localhost if no host given
//
func TcHost(hname string) Option {
return func(s *OtfAlignService) error {
if hname != "" {
s.tcHost = hname
return nil
}
s.tcHost = "localhost"
return nil
}
}
//
// set the port of the text classifier web service
// defaults to 1576 (otf-classifier default port)
//
func TcPort(port int) Option {
return func(s *OtfAlignService) error {
if port != 0 {
s.tcPort = port
return nil
}
s.tcPort = 1576
return nil
}
}