cmd: drop grace package dependency

Note that signal.NotifyContext is a Go 1.16 feature.

Signed-off-by: Roman Khimov <roman@nspcc.ru>
This commit is contained in:
Roman Khimov 2021-05-25 13:30:54 +03:00
parent 787c6836aa
commit 69e3e22dbc
3 changed files with 18 additions and 11 deletions

View file

@ -6,12 +6,13 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"os" "os"
"os/signal"
"syscall"
"time" "time"
sdk "github.com/nspcc-dev/cdn-sdk" sdk "github.com/nspcc-dev/cdn-sdk"
"github.com/nspcc-dev/cdn-sdk/creds/hcs" "github.com/nspcc-dev/cdn-sdk/creds/hcs"
"github.com/nspcc-dev/cdn-sdk/creds/neofs" "github.com/nspcc-dev/cdn-sdk/creds/neofs"
"github.com/nspcc-dev/cdn-sdk/grace"
"github.com/nspcc-dev/cdn-sdk/pool" "github.com/nspcc-dev/cdn-sdk/pool"
"github.com/nspcc-dev/neofs-api-go/pkg/container" "github.com/nspcc-dev/neofs-api-go/pkg/container"
"github.com/nspcc-dev/neofs-s3-gw/authmate" "github.com/nspcc-dev/neofs-s3-gw/authmate"
@ -64,12 +65,13 @@ var zapConfig = zap.Config{
func prepare() (context.Context, *zap.Logger) { func prepare() (context.Context, *zap.Logger) {
var ( var (
err error err error
log = zap.NewNop() log = zap.NewNop()
ctx, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM, syscall.SIGHUP)
) )
if !logEnabledFlag { if !logEnabledFlag {
return grace.Context(log), log return ctx, log
} else if logDebugEnabledFlag { } else if logDebugEnabledFlag {
zapConfig.Level = zap.NewAtomicLevelAt(zapcore.DebugLevel) zapConfig.Level = zap.NewAtomicLevelAt(zapcore.DebugLevel)
} }
@ -78,7 +80,7 @@ func prepare() (context.Context, *zap.Logger) {
panic(err) panic(err)
} }
return grace.Context(log), log return ctx, log
} }
func main() { func main() {

View file

@ -1,7 +1,10 @@
package main package main
import ( import (
"github.com/nspcc-dev/cdn-sdk/grace" "context"
"os/signal"
"syscall"
"github.com/nspcc-dev/cdn-sdk/logger" "github.com/nspcc-dev/cdn-sdk/logger"
"github.com/spf13/viper" "github.com/spf13/viper"
"go.uber.org/zap" "go.uber.org/zap"
@ -39,10 +42,10 @@ func newLogger(v *viper.Viper) *zap.Logger {
func main() { func main() {
var ( var (
v = newSettings() v = newSettings()
l = newLogger(v) l = newLogger(v)
g = grace.Context(l) g, _ = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM, syscall.SIGHUP)
a = newApp(g, l, v) a = newApp(g, l, v)
) )
go a.Server(g) go a.Server(g)

4
go.mod
View file

@ -1,6 +1,6 @@
module github.com/nspcc-dev/neofs-s3-gw module github.com/nspcc-dev/neofs-s3-gw
go 1.14 go 1.16
require ( require (
github.com/aws/aws-sdk-go v1.37.9 github.com/aws/aws-sdk-go v1.37.9
@ -8,6 +8,7 @@ require (
github.com/gorilla/mux v1.8.0 github.com/gorilla/mux v1.8.0
github.com/nspcc-dev/cdn-sdk v0.3.4 github.com/nspcc-dev/cdn-sdk v0.3.4
github.com/nspcc-dev/neofs-api-go v1.23.0 github.com/nspcc-dev/neofs-api-go v1.23.0
github.com/nspcc-dev/neofs-crypto v0.3.0
github.com/nspcc-dev/neofs-node v1.22.0 github.com/nspcc-dev/neofs-node v1.22.0
github.com/prometheus/client_golang v1.9.0 github.com/prometheus/client_golang v1.9.0
github.com/spf13/pflag v1.0.5 github.com/spf13/pflag v1.0.5
@ -15,5 +16,6 @@ require (
github.com/stretchr/testify v1.7.0 github.com/stretchr/testify v1.7.0
github.com/urfave/cli/v2 v2.3.0 github.com/urfave/cli/v2 v2.3.0
go.uber.org/zap v1.16.0 go.uber.org/zap v1.16.0
golang.org/x/crypto v0.0.0-20201002170205-7f63de1d35b0
google.golang.org/grpc v1.35.0 google.golang.org/grpc v1.35.0
) )