From 3c325b341b5a65b6c81becba20a451a861e3894a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Viktor=20Tigerstr=C3=B6m?= Date: Thu, 14 Dec 2023 01:12:42 +0100 Subject: [PATCH] status: unexport SubServerStatus & rename to subServer --- status/manager.go | 62 +++++++++++++++++++++++------------------------ 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/status/manager.go b/status/manager.go index 4caae5010..83c0d5bce 100644 --- a/status/manager.go +++ b/status/manager.go @@ -10,28 +10,28 @@ import ( ) // SubServerOption defines a functional option that can be used to modify the -// values of a SubServerStatus's fields. -type SubServerOption func(status *SubServerStatus) +// values of a subServer's fields. +type SubServerOption func(status *subServer) // WithIsReadyOverride is a functional option that can be used to set a call // back function that is used to check if a system is ready _iff_ the system // running status is not yet true. The call-back will be passed the request URI // along with any manual status that has been set for the subsystem. func WithIsReadyOverride(fn func(string, string) (bool, bool)) SubServerOption { - return func(status *SubServerStatus) { + return func(status *subServer) { status.isReadyOverride = fn } } -// SubServerStatus represents the status of a sub-server. -type SubServerStatus struct { - // Disabled is true if the sub-server is available in the LiT bundle but +// subServer represents the status of a sub-server. +type subServer struct { + // disabled is true if the sub-server is available in the LiT bundle but // has explicitly been disabled by the user. - Disabled bool + disabled bool - // Running is true if the sub-server is enabled and has successfully + // running is true if the sub-server is enabled and has successfully // been started. - Running bool + running bool // manualStatus will be a non-empty string that details the current // status of the sub-server. This status can be set to a unique status @@ -39,8 +39,8 @@ type SubServerStatus struct { // to the user with the litrpc.SubServerStatus. manualStatus string - // Err will be a non-empty string if the sub-server failed to start. - Err string + // err will be a non-empty string if the sub-server failed to start. + err string // isReadyOverride is a call back that, when set and only if `running` // is not yet true, will be used to determine if a system is ready for @@ -52,10 +52,10 @@ type SubServerStatus struct { isReadyOverride func(string, string) (bool, bool) } -// newSubServerStatus constructs a new SubServerStatus. -func newSubServerStatus(disabled bool) *SubServerStatus { - return &SubServerStatus{ - Disabled: disabled, +// newSubServer constructs a new subServer. +func newSubServer(disabled bool) *subServer { + return &subServer{ + disabled: disabled, } } @@ -65,14 +65,14 @@ func newSubServerStatus(disabled bool) *SubServerStatus { type Manager struct { litrpc.UnimplementedStatusServer - subServers map[string]*SubServerStatus + subServers map[string]*subServer mu sync.RWMutex } // NewStatusManager constructs a new Manager. func NewStatusManager() *Manager { return &Manager{ - subServers: make(map[string]*SubServerStatus), + subServers: make(map[string]*subServer), } } @@ -90,14 +90,14 @@ func (s *Manager) IsSystemReady(name, req string) (bool, bool, error) { "name %s has not yet been registered") } - if server.Disabled { + if server.disabled { return false, true, nil } // If this system has an override check set, then we first check that // to see if it overrides the "ready" status of the system in case the // system isn't marked as running yet. - if server.isReadyOverride != nil && !server.Running { + if server.isReadyOverride != nil && !server.running { isReady, handled := server.isReadyOverride( req, server.manualStatus, ) @@ -106,7 +106,7 @@ func (s *Manager) IsSystemReady(name, req string) (bool, bool, error) { } } - return server.Running, false, nil + return server.running, false, nil } // SubServerStatus queries the current status of a given sub-server. @@ -122,9 +122,9 @@ func (s *Manager) SubServerStatus(_ context.Context, resp := make(map[string]*litrpc.SubServerStatus, len(s.subServers)) for server, status := range s.subServers { resp[server] = &litrpc.SubServerStatus{ - Disabled: status.Disabled, - Running: status.Running, - Error: status.Err, + Disabled: status.disabled, + Running: status.running, + Error: status.err, Status: status.manualStatus, } } @@ -157,7 +157,7 @@ func (s *Manager) RegisterAndEnableSubServer(name string, func (s *Manager) registerSubServerUnsafe(name string, disabled bool, opts ...SubServerOption) { - ss := newSubServerStatus(disabled) + ss := newSubServer(disabled) ss.manualStatus = "Registered" for _, o := range opts { @@ -196,7 +196,7 @@ func (s *Manager) SetEnabled(name string) { return } - ss.Disabled = false + ss.disabled = false } // SetRunning can be used to set the status of a sub-server as Running @@ -215,8 +215,8 @@ func (s *Manager) SetRunning(name string) { return } - ss.Running = true - ss.Err = "" + ss.running = true + ss.err = "" ss.manualStatus = "Running" } @@ -236,8 +236,8 @@ func (s *Manager) SetStopped(name string) { return } - ss.Running = false - ss.Err = "" + ss.running = false + ss.err = "" ss.manualStatus = "Stopped" } @@ -262,7 +262,7 @@ func (s *Manager) SetErrored(name string, errStr string, err := fmt.Sprintf(errStr, params...) log.Errorf("could not start the %s sub-server: %s", name, err) - ss.Running = false - ss.Err = err + ss.running = false + ss.err = err ss.manualStatus = "Errored" }