@@ -23,6 +23,13 @@ type SubServerStatus struct {
2323 // been started.
2424 Running bool
2525
26+ // customStatus is a string that details a custom status of the
27+ // sub-server, if the the sub-server is in a custom state. This status
28+ // can be set to a unique status that only exists for the specific
29+ // sub-server, and will be displayed to the user with the
30+ // litrpc.SubServerStatus.
31+ customStatus string
32+
2633 // Err will be a non-empty string if the sub-server failed to start.
2734 Err string
2835}
@@ -107,6 +114,20 @@ func (s *Manager) registerSubServerUnsafe(name string, disabled bool,
107114 s .subServers [name ] = ss
108115}
109116
117+ // SetCustomStatus updates the custom status of the given sub-server to the
118+ // passed status.
119+ func (s * Manager ) SetCustomStatus (name , customStatus string ) {
120+ s .mu .Lock ()
121+ defer s .mu .Unlock ()
122+
123+ ss , ok := s .subServers [name ]
124+ if ! ok {
125+ return
126+ }
127+
128+ ss .customStatus = customStatus
129+ }
130+
110131// GetStatus returns the current status of a given sub-server. This will
111132// silently fail if the referenced sub-server has not yet been registered.
112133func (s * Manager ) GetStatus (name string ) (* SubServerStatus , error ) {
@@ -157,6 +178,7 @@ func (s *Manager) SetRunning(name string) {
157178 }
158179
159180 ss .Running = true
181+ ss .customStatus = ""
160182}
161183
162184// SetStopped can be used to set the status of a sub-server as not Running and
@@ -177,6 +199,7 @@ func (s *Manager) SetStopped(name string) {
177199
178200 ss .Running = false
179201 ss .Err = ""
202+ ss .customStatus = ""
180203}
181204
182205// SetErrored can be used to set the status of a sub-server as not Running
@@ -202,4 +225,5 @@ func (s *Manager) SetErrored(name string, errStr string,
202225
203226 ss .Running = false
204227 ss .Err = err
228+ ss .customStatus = ""
205229}
0 commit comments