Skip to content

Commit fcd22a7

Browse files
status: unexport SubServerStatus & rename to subServer
1 parent 33d6f6e commit fcd22a7

File tree

1 file changed

+32
-34
lines changed

1 file changed

+32
-34
lines changed

status/manager.go

+32-34
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,28 @@ import (
1010
)
1111

1212
// 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)
1515

1616
// WithIsReadyOverride is a functional option that can be used to set a callback
1717
// function that is used to check if a system is ready _iff_ the system running
1818
// status is not yet true. The call-back will be passed the request URI along
1919
// with any manual status that has been set for the subsystem.
2020
func WithIsReadyOverride(fn func(string, string) (bool, bool)) SubServerOption {
21-
return func(status *SubServerStatus) {
21+
return func(status *subServer) {
2222
status.isReadyOverride = fn
2323
}
2424
}
2525

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
2929
// has explicitly been disabled by the user.
30-
Disabled bool
30+
disabled bool
3131

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
3333
// been started.
34-
Running bool
34+
running bool
3535

3636
// customStatus is a string that details a custom status of the
3737
// sub-server, if the the sub-server is in a custom state. This status
@@ -40,8 +40,8 @@ type SubServerStatus struct {
4040
// litrpc.SubServerStatus.
4141
customStatus string
4242

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
4545

4646
// isReadyOverride is a call back that, when set and only if `running`
4747
// is not yet true, will be used to determine if a system is ready for
@@ -53,12 +53,10 @@ type SubServerStatus struct {
5353
isReadyOverride func(string, string) (bool, bool)
5454
}
5555

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,
6260
}
6361
}
6462

@@ -68,14 +66,14 @@ func newSubServerStatus(disabled bool,
6866
type Manager struct {
6967
litrpc.UnimplementedStatusServer
7068

71-
subServers map[string]*SubServerStatus
69+
subServers map[string]*subServer
7270
mu sync.RWMutex
7371
}
7472

7573
// NewStatusManager constructs a new Manager.
7674
func NewStatusManager() *Manager {
7775
return &Manager{
78-
subServers: make(map[string]*SubServerStatus),
76+
subServers: make(map[string]*subServer),
7977
}
8078
}
8179

@@ -93,14 +91,14 @@ func (s *Manager) IsSystemReady(name, req string) (bool, bool, error) {
9391
"name %s has not yet been registered")
9492
}
9593

96-
if server.Disabled {
94+
if server.disabled {
9795
return false, true, nil
9896
}
9997

10098
// If there is no override for this server or if the server is already
10199
// 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
104102
}
105103

106104
// 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) {
111109
}
112110

113111
// Otherwise, we just return the running status.
114-
return server.Running, false, nil
112+
return server.running, false, nil
115113
}
116114

117115
// SubServerStatus queries the current status of a given sub-server.
@@ -127,9 +125,9 @@ func (s *Manager) SubServerStatus(_ context.Context,
127125
resp := make(map[string]*litrpc.SubServerStatus, len(s.subServers))
128126
for server, status := range s.subServers {
129127
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,
133131
CustomStatus: status.customStatus,
134132
}
135133
}
@@ -162,7 +160,7 @@ func (s *Manager) RegisterAndEnableSubServer(name string,
162160
func (s *Manager) registerSubServerUnsafe(name string, disabled bool,
163161
opts ...SubServerOption) {
164162

165-
ss := newSubServerStatus(disabled, opts...)
163+
ss := newSubServer(disabled, opts...)
166164

167165
s.subServers[name] = ss
168166
}
@@ -196,7 +194,7 @@ func (s *Manager) SetEnabled(name string) {
196194
return
197195
}
198196

199-
ss.Disabled = false
197+
ss.disabled = false
200198
}
201199

202200
// SetRunning can be used to set the status of a sub-server as Running
@@ -215,8 +213,8 @@ func (s *Manager) SetRunning(name string) {
215213
return
216214
}
217215

218-
ss.Running = true
219-
ss.Err = ""
216+
ss.running = true
217+
ss.err = ""
220218
ss.customStatus = ""
221219
}
222220

@@ -236,8 +234,8 @@ func (s *Manager) SetStopped(name string) {
236234
return
237235
}
238236

239-
ss.Running = false
240-
ss.Err = ""
237+
ss.running = false
238+
ss.err = ""
241239
ss.customStatus = ""
242240
}
243241

@@ -263,7 +261,7 @@ func (s *Manager) SetErrored(name string, errStr string,
263261

264262
log.Errorf("could not start the %s sub-server: %s", name, err)
265263

266-
ss.Running = false
267-
ss.Err = err
264+
ss.running = false
265+
ss.err = err
268266
ss.customStatus = ""
269267
}

0 commit comments

Comments
 (0)