From cdab794d6218fdfee354fbd029e188a9f3396edb Mon Sep 17 00:00:00 2001 From: Pavel Korotkov Date: Thu, 25 Mar 2021 11:27:59 +0300 Subject: [PATCH] Remove sdk context dep Signed-off-by: Pavel Korotkov --- global/context.go | 20 ++++++++++++++++++++ main.go | 11 +++-------- 2 files changed, 23 insertions(+), 8 deletions(-) create mode 100644 global/context.go diff --git a/global/context.go b/global/context.go new file mode 100644 index 0000000..6aa6754 --- /dev/null +++ b/global/context.go @@ -0,0 +1,20 @@ +package global + +import ( + "context" + "os/signal" + "sync" + "syscall" +) + +var ( + globalContext context.Context + globalContexOnce sync.Once +) + +func Context() context.Context { + globalContexOnce.Do(func() { + globalContext, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM, syscall.SIGHUP) + }) + return globalContext +} diff --git a/main.go b/main.go index 770d5a8..3fb5c6c 100644 --- a/main.go +++ b/main.go @@ -1,8 +1,8 @@ package main import ( - "github.com/nspcc-dev/cdn-sdk/grace" "github.com/nspcc-dev/cdn-sdk/logger" + "github.com/nspcc-dev/neofs-http-gate/global" "github.com/spf13/viper" "go.uber.org/zap" ) @@ -41,15 +41,10 @@ func main() { var ( v = settings() l = newLogger(v) - g = grace.Context(l) - - a = newApp(g, - WithLogger(l), - WithConfig(v)) + g = global.Context() + a = newApp(g, WithLogger(l), WithConfig(v)) ) - go a.Serve(g) go a.Worker(g) - a.Wait() }