diff --git a/context/context.go b/context/context.go index ecd4f58..ae94627 100644 --- a/context/context.go +++ b/context/context.go @@ -8,7 +8,7 @@ import ( "github.com/rs/zerolog" "gopkg.in/yaml.v2" "io/ioutil" - "lab.wtfteam.pro/fat0troll/fw_zookeeper_helper/local/config" + "lab.wtfteam.pro/fat0troll/fw_zookeeper_helper/internal/config" "os" "path/filepath" "runtime" diff --git a/context/exported.go b/context/exported.go index e88e801..3d5f412 100644 --- a/context/exported.go +++ b/context/exported.go @@ -5,7 +5,7 @@ package context import ( "github.com/rs/zerolog" - "lab.wtfteam.pro/fat0troll/fw_zookeeper_helper/local/config" + "lab.wtfteam.pro/fat0troll/fw_zookeeper_helper/internal/config" ) // VERSION is the current bot's version @@ -13,14 +13,12 @@ const VERSION = "0.0.2" // Context is the main application context. type Context struct { - Config *config.Struct - Logger zerolog.Logger - ShutdownDone chan bool + Config *config.Struct + Logger zerolog.Logger } // NewContext is an initialization function for Context func NewContext() *Context { c := &Context{} - c.ShutdownDone = make(chan bool, 1) return c } diff --git a/domains/announces/v1/announces.go b/domains/announces/v1/announces.go index 5baf303..24e6a5f 100644 --- a/domains/announces/v1/announces.go +++ b/domains/announces/v1/announces.go @@ -72,8 +72,5 @@ func ZookeeperReceiver(client *tdlib.Client) { } } } - - <-c.ShutdownDone - return }() } diff --git a/go.mod b/go.mod index 15f7f59..a88e888 100644 --- a/go.mod +++ b/go.mod @@ -3,5 +3,6 @@ module lab.wtfteam.pro/fat0troll/fw_zookeeper_helper require ( github.com/Arman92/go-tdlib v0.0.0-20181103144727-9577ff528640 github.com/rs/zerolog v1.11.0 + gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect gopkg.in/yaml.v2 v2.2.2 ) diff --git a/go.sum b/go.sum index 5a55057..e35cc49 100644 --- a/go.sum +++ b/go.sum @@ -4,5 +4,6 @@ github.com/rs/zerolog v1.11.0 h1:DRuq/S+4k52uJzBQciUcofXx45GrMC6yrEbb/CoK6+M= github.com/rs/zerolog v1.11.0/go.mod h1:YbFCdg8HfsridGWAh22vktObvhZbQsZXe4/zB0OKkWU= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/local/config/announce.go b/internal/config/announce.go similarity index 100% rename from local/config/announce.go rename to internal/config/announce.go diff --git a/local/config/struct.go b/internal/config/struct.go similarity index 100% rename from local/config/struct.go rename to internal/config/struct.go diff --git a/local/config/tdlib.go b/internal/config/tdlib.go similarity index 100% rename from local/config/tdlib.go rename to internal/config/tdlib.go diff --git a/local/telegram/exported.go b/internal/telegram/exported.go similarity index 100% rename from local/telegram/exported.go rename to internal/telegram/exported.go diff --git a/local/telegram/telegram.go b/internal/telegram/telegram.go similarity index 98% rename from local/telegram/telegram.go rename to internal/telegram/telegram.go index 298c4e2..b03084b 100644 --- a/local/telegram/telegram.go +++ b/internal/telegram/telegram.go @@ -73,9 +73,6 @@ func Authenticate() { func Connect() { go func() { announcesv1.ZookeeperReceiver(client) - - <-c.ShutdownDone - return }() rawUpdates := client.GetRawUpdatesChannel(100) log.Debug().Msg("Connection with Telegram established") diff --git a/main.go b/main.go index c4dea95..96ba018 100644 --- a/main.go +++ b/main.go @@ -6,7 +6,7 @@ package main import ( "lab.wtfteam.pro/fat0troll/fw_zookeeper_helper/context" "lab.wtfteam.pro/fat0troll/fw_zookeeper_helper/domains/announces/v1" - "lab.wtfteam.pro/fat0troll/fw_zookeeper_helper/local/telegram" + "lab.wtfteam.pro/fat0troll/fw_zookeeper_helper/internal/telegram" "os" "os/signal" "runtime" @@ -19,14 +19,17 @@ func main() { runtime.LockOSThread() // Initializing context - c := context.NewContext() c.Init() c.InitConfiguration() + announcesv1.New(c) + telegram.New(c) + // CTRL+C handler. interrupt := make(chan os.Signal, 1) signal.Notify(interrupt) + shutdownDone := make(chan bool, 1) go func() { signalThing := <-interrupt if signalThing == syscall.SIGTERM || signalThing == syscall.SIGINT { @@ -34,14 +37,11 @@ func main() { telegram.Shutdown() - c.ShutdownDone <- true + shutdownDone <- true } }() - announcesv1.New(c) - telegram.New(c) - - <-c.ShutdownDone + <-shutdownDone os.Exit(0) }