@@ -10,28 +10,28 @@ import (
10
10
)
11
11
12
12
// SubServerOption defines a functional option that can be used to modify the
13
- // values of a SubServerStatus 's fields.
14
- type SubServerOption func (status * SubServerStatus )
13
+ // values of a subServer 's fields.
14
+ type SubServerOption func (status * subServer )
15
15
16
16
// WithIsReadyOverride is a functional option that can be used to set a callback
17
17
// function that is used to check if a system is ready _iff_ the system running
18
18
// status is not yet true. The call-back will be passed the request URI along
19
19
// with any manual status that has been set for the subsystem.
20
20
func WithIsReadyOverride (fn func (string , string ) (bool , bool )) SubServerOption {
21
- return func (status * SubServerStatus ) {
21
+ return func (status * subServer ) {
22
22
status .isReadyOverride = fn
23
23
}
24
24
}
25
25
26
- // SubServerStatus represents the status of a sub-server.
27
- type SubServerStatus struct {
28
- // Disabled is true if the sub-server is available in the LiT bundle but
26
+ // subServer represents the status of a sub-server.
27
+ type subServer struct {
28
+ // disabled is true if the sub-server is available in the LiT bundle but
29
29
// has explicitly been disabled by the user.
30
- Disabled bool
30
+ disabled bool
31
31
32
- // Running is true if the sub-server is enabled and has successfully
32
+ // running is true if the sub-server is enabled and has successfully
33
33
// been started.
34
- Running bool
34
+ running bool
35
35
36
36
// customStatus is a string that details a custom status of the
37
37
// sub-server, if the the sub-server is in a custom state. This status
@@ -40,8 +40,8 @@ type SubServerStatus struct {
40
40
// litrpc.SubServerStatus.
41
41
customStatus string
42
42
43
- // Err will be a non-empty string if the sub-server failed to start.
44
- Err string
43
+ // err will be a non-empty string if the sub-server failed to start.
44
+ err string
45
45
46
46
// isReadyOverride is a call back that, when set and only if `running`
47
47
// is not yet true, will be used to determine if a system is ready for
@@ -53,12 +53,10 @@ type SubServerStatus struct {
53
53
isReadyOverride func (string , string ) (bool , bool )
54
54
}
55
55
56
- // newSubServerStatus constructs a new SubServerStatus.
57
- func newSubServerStatus (disabled bool ,
58
- opts ... SubServerOption ) * SubServerStatus {
59
-
60
- return & SubServerStatus {
61
- Disabled : disabled ,
56
+ // newSubServer constructs a new subServer.
57
+ func newSubServer (disabled bool , opts ... SubServerOption ) * subServer {
58
+ return & subServer {
59
+ disabled : disabled ,
62
60
}
63
61
}
64
62
@@ -68,14 +66,14 @@ func newSubServerStatus(disabled bool,
68
66
type Manager struct {
69
67
litrpc.UnimplementedStatusServer
70
68
71
- subServers map [string ]* SubServerStatus
69
+ subServers map [string ]* subServer
72
70
mu sync.RWMutex
73
71
}
74
72
75
73
// NewStatusManager constructs a new Manager.
76
74
func NewStatusManager () * Manager {
77
75
return & Manager {
78
- subServers : make (map [string ]* SubServerStatus ),
76
+ subServers : make (map [string ]* subServer ),
79
77
}
80
78
}
81
79
@@ -93,14 +91,14 @@ func (s *Manager) IsSystemReady(name, req string) (bool, bool, error) {
93
91
"name %s has not yet been registered" )
94
92
}
95
93
96
- if server .Disabled {
94
+ if server .disabled {
97
95
return false , true , nil
98
96
}
99
97
100
98
// If there is no override for this server or if the server is already
101
99
// running then we just return the 'running' status.
102
- if server .isReadyOverride == nil || server .Running {
103
- return server .Running , false , nil
100
+ if server .isReadyOverride == nil || server .running {
101
+ return server .running , false , nil
104
102
}
105
103
106
104
// Otherwise, we check the override to see if this request is handled
@@ -111,7 +109,7 @@ func (s *Manager) IsSystemReady(name, req string) (bool, bool, error) {
111
109
}
112
110
113
111
// Otherwise, we just return the running status.
114
- return server .Running , false , nil
112
+ return server .running , false , nil
115
113
}
116
114
117
115
// SubServerStatus queries the current status of a given sub-server.
@@ -127,9 +125,9 @@ func (s *Manager) SubServerStatus(_ context.Context,
127
125
resp := make (map [string ]* litrpc.SubServerStatus , len (s .subServers ))
128
126
for server , status := range s .subServers {
129
127
resp [server ] = & litrpc.SubServerStatus {
130
- Disabled : status .Disabled ,
131
- Running : status .Running ,
132
- Error : status .Err ,
128
+ Disabled : status .disabled ,
129
+ Running : status .running ,
130
+ Error : status .err ,
133
131
CustomStatus : status .customStatus ,
134
132
}
135
133
}
@@ -162,7 +160,7 @@ func (s *Manager) RegisterAndEnableSubServer(name string,
162
160
func (s * Manager ) registerSubServerUnsafe (name string , disabled bool ,
163
161
opts ... SubServerOption ) {
164
162
165
- ss := newSubServerStatus (disabled , opts ... )
163
+ ss := newSubServer (disabled , opts ... )
166
164
167
165
s .subServers [name ] = ss
168
166
}
@@ -196,7 +194,7 @@ func (s *Manager) SetEnabled(name string) {
196
194
return
197
195
}
198
196
199
- ss .Disabled = false
197
+ ss .disabled = false
200
198
}
201
199
202
200
// SetRunning can be used to set the status of a sub-server as Running
@@ -215,8 +213,8 @@ func (s *Manager) SetRunning(name string) {
215
213
return
216
214
}
217
215
218
- ss .Running = true
219
- ss .Err = ""
216
+ ss .running = true
217
+ ss .err = ""
220
218
ss .customStatus = ""
221
219
}
222
220
@@ -236,8 +234,8 @@ func (s *Manager) SetStopped(name string) {
236
234
return
237
235
}
238
236
239
- ss .Running = false
240
- ss .Err = ""
237
+ ss .running = false
238
+ ss .err = ""
241
239
ss .customStatus = ""
242
240
}
243
241
@@ -263,7 +261,7 @@ func (s *Manager) SetErrored(name string, errStr string,
263
261
264
262
log .Errorf ("could not start the %s sub-server: %s" , name , err )
265
263
266
- ss .Running = false
267
- ss .Err = err
264
+ ss .running = false
265
+ ss .err = err
268
266
ss .customStatus = ""
269
267
}
0 commit comments