mirror of
https://github.com/fumiama/terasu-cloudflared.git
synced 2026-06-05 00:50:24 +08:00
AUTH-2169 make access login page more generic
This commit is contained in:
@@ -1,14 +1,20 @@
|
||||
package overwatch
|
||||
|
||||
// ServiceCallback is a service notify it's runloop finished.
|
||||
// the first parameter is the service type
|
||||
// the second parameter is the service name
|
||||
// the third parameter is an optional error if the service failed
|
||||
type ServiceCallback func(string, string, error)
|
||||
|
||||
// AppManager is the default implementation of overwatch service management
|
||||
type AppManager struct {
|
||||
services map[string]Service
|
||||
errorChan chan error
|
||||
services map[string]Service
|
||||
callback ServiceCallback
|
||||
}
|
||||
|
||||
// NewAppManager creates a new overwatch manager
|
||||
func NewAppManager(errorChan chan error) Manager {
|
||||
return &AppManager{services: make(map[string]Service), errorChan: errorChan}
|
||||
func NewAppManager(callback ServiceCallback) Manager {
|
||||
return &AppManager{services: make(map[string]Service), callback: callback}
|
||||
}
|
||||
|
||||
// Add takes in a new service to manage.
|
||||
@@ -47,7 +53,7 @@ func (m *AppManager) Services() []Service {
|
||||
|
||||
func (m *AppManager) serviceRun(service Service) {
|
||||
err := service.Run()
|
||||
if err != nil && m.errorChan != nil {
|
||||
m.errorChan <- err
|
||||
if m.callback != nil {
|
||||
m.callback(service.Type(), service.Name(), err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,7 +64,10 @@ func TestManagerDuplicate(t *testing.T) {
|
||||
|
||||
func TestManagerErrorChannel(t *testing.T) {
|
||||
errChan := make(chan error)
|
||||
m := NewAppManager(errChan)
|
||||
serviceCallback := func(t string, name string, err error) {
|
||||
errChan <- err
|
||||
}
|
||||
m := NewAppManager(serviceCallback)
|
||||
|
||||
err := errors.New("test error")
|
||||
first := &mockService{serviceName: "first", serviceType: "mock", runError: err}
|
||||
|
||||
Reference in New Issue
Block a user