From e6f66ad7f0f039647598e23930cddab98e151616 Mon Sep 17 00:00:00 2001 From: crusader Date: Mon, 26 Mar 2018 12:50:29 +0900 Subject: [PATCH] ing --- auth/auth.go | 10 +++++++--- commons/endable_starter.go | 5 ----- commons/shutdowner.go | 7 ------- commons/starter.go | 5 ----- main.go | 8 ++++---- probe/probe.go | 11 +++++++---- service/service.go | 6 ++++++ 7 files changed, 24 insertions(+), 28 deletions(-) delete mode 100644 commons/endable_starter.go delete mode 100644 commons/shutdowner.go delete mode 100644 commons/starter.go diff --git a/auth/auth.go b/auth/auth.go index ab9f0c1..b0beaf3 100644 --- a/auth/auth.go +++ b/auth/auth.go @@ -1,6 +1,7 @@ package auth import ( + "context" "fmt" "path" "sync" @@ -9,6 +10,7 @@ import ( "git.loafle.net/commons_go/logging" crr "git.loafle.net/commons_go/rpc/registry" ooccn "git.loafle.net/overflow/overflow_commons_go/config/noauthprobe" + oocmci "git.loafle.net/overflow/overflow_commons_go/modules/commons/interfaces" oogwc "git.loafle.net/overflow/overflow_gateway_websocket/client" "git.loafle.net/overflow/overflow_probes/auth/client" oopas "git.loafle.net/overflow/overflow_probes/auth/service" @@ -22,8 +24,8 @@ func New() AuthManager { } type AuthManager interface { - EndableStart(doneChan chan<- error) error - Stop() + oocmci.EndableStarter + oocmci.Stopper } type authManagers struct { @@ -85,8 +87,10 @@ func (am *authManagers) EndableStart(doneChan chan<- error) error { return nil } -func (am *authManagers) Stop() { +func (am *authManagers) Stop(ctx context.Context) error { am.destroy(nil) + + return nil } func (am *authManagers) destroy(err error) { diff --git a/commons/endable_starter.go b/commons/endable_starter.go deleted file mode 100644 index 6304e59..0000000 --- a/commons/endable_starter.go +++ /dev/null @@ -1,5 +0,0 @@ -package commons - -type EndableStarter interface { - EndableStart(endded chan<- error) error -} diff --git a/commons/shutdowner.go b/commons/shutdowner.go deleted file mode 100644 index ac1a704..0000000 --- a/commons/shutdowner.go +++ /dev/null @@ -1,7 +0,0 @@ -package commons - -import "context" - -type Shutdowner interface { - Shutdown(ctx context.Context) error -} diff --git a/commons/starter.go b/commons/starter.go deleted file mode 100644 index a6d0f03..0000000 --- a/commons/starter.go +++ /dev/null @@ -1,5 +0,0 @@ -package commons - -type Starter interface { - Start() error -} diff --git a/main.go b/main.go index 0ad5a09..a1689b5 100644 --- a/main.go +++ b/main.go @@ -14,8 +14,8 @@ import ( "git.loafle.net/commons_go/logging" oocc "git.loafle.net/overflow/overflow_commons_go/config" ooccp "git.loafle.net/overflow/overflow_commons_go/config/probe" + oocmci "git.loafle.net/overflow/overflow_commons_go/modules/commons/interfaces" "git.loafle.net/overflow/overflow_probes/auth" - "git.loafle.net/overflow/overflow_probes/commons" "git.loafle.net/overflow/overflow_probes/config" "git.loafle.net/overflow/overflow_probes/probe" ) @@ -71,7 +71,7 @@ func main() { authDoneChan := make(chan error, 1) defer close(authDoneChan) - if err := instance.(commons.EndableStarter).EndableStart(authDoneChan); err != nil { + if err := instance.(oocmci.EndableStarter).EndableStart(authDoneChan); err != nil { logging.Logger().Error(err) os.Exit(1) } @@ -82,7 +82,7 @@ func main() { } } instance = probe.New() - if err := instance.(commons.Starter).Start(); err != nil { + if err := instance.(oocmci.Starter).Start(); err != nil { logging.Logger().Error(err) os.Exit(1) } @@ -104,7 +104,7 @@ func main() { <-interrupt ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) defer cancel() - if err := instance.(commons.Shutdowner).Shutdown(ctx); err != nil { + if err := instance.(oocmci.Stopper).Stop(ctx); err != nil { logging.Logger().Errorf("Probe error: %v", err) } diff --git a/probe/probe.go b/probe/probe.go index 29646b2..370f412 100644 --- a/probe/probe.go +++ b/probe/probe.go @@ -1,11 +1,13 @@ package probe import ( + "context" "sync" cdr "git.loafle.net/commons_go/di/registry" "git.loafle.net/commons_go/logging" crr "git.loafle.net/commons_go/rpc/registry" + oocmci "git.loafle.net/overflow/overflow_commons_go/modules/commons/interfaces" oocmp "git.loafle.net/overflow/overflow_commons_go/modules/probe" oogwc "git.loafle.net/overflow/overflow_gateway_websocket/client" oopccd "git.loafle.net/overflow/overflow_probes/client/central/data" @@ -21,8 +23,8 @@ func New() ProbeManager { } type ProbeManager interface { - Start() error - Stop() + oocmci.Starter + oocmci.Stopper } type probeManagers struct { @@ -78,7 +80,7 @@ func (pm *probeManagers) Start() error { return nil } -func (pm *probeManagers) Stop() { +func (pm *probeManagers) Stop(ctx context.Context) error { if pm.stopChan == nil { logging.Logger().Warnf("Probe: probe must be started before stopping it") } @@ -90,13 +92,14 @@ func (pm *probeManagers) Stop() { logging.Logger().Infof("Probe: stopped") + return nil } func (pm *probeManagers) handleProbe() { // var err error defer func() { pm.stopWg.Done() - pm.Stop() + pm.Stop(nil) }() // if err = pm.cClient.Connect(); nil != err { diff --git a/service/service.go b/service/service.go index 113dbea..801caa9 100644 --- a/service/service.go +++ b/service/service.go @@ -3,6 +3,12 @@ package service func InitService() { } +func StartService() { +} + +func StopService() { +} + func DestroyService() { }