[#19] Add a version with no cdn-sdk deps

Signed-off-by: Pavel Korotkov <pavel@nspcc.ru>
This commit is contained in:
Pavel Korotkov 2021-03-31 01:46:33 +03:00 committed by Pavel Korotkov
parent cdab794d62
commit 4c96885a42
20 changed files with 930 additions and 266 deletions

65
main.go
View file

@ -1,50 +1,43 @@
package main
import (
"github.com/nspcc-dev/cdn-sdk/logger"
"github.com/nspcc-dev/neofs-http-gate/global"
"github.com/nspcc-dev/neofs-http-gate/logger"
"github.com/spf13/viper"
"go.uber.org/zap"
)
func newLogger(v *viper.Viper) *zap.Logger {
options := []logger.Option{
logger.WithLevel(v.GetString(cfgLoggerLevel)),
logger.WithTraceLevel(v.GetString(cfgLoggerTraceLevel)),
logger.WithFormat(v.GetString(cfgLoggerFormat)),
logger.WithSamplingInitial(v.GetInt(cfgLoggerSamplingInitial)),
logger.WithSamplingThereafter(v.GetInt(cfgLoggerSamplingThereafter)),
logger.WithAppName(v.GetString(cfgApplicationName)),
logger.WithAppVersion(v.GetString(cfgApplicationVersion)),
}
if v.GetBool(cfgLoggerNoCaller) {
options = append(options, logger.WithoutCaller())
}
if v.GetBool(cfgLoggerNoDisclaimer) {
options = append(options, logger.WithoutDisclaimer())
}
l, err := logger.New(options...)
if err != nil {
panic(err)
}
return l
}
func main() {
var (
v = settings()
l = newLogger(v)
g = global.Context()
a = newApp(g, WithLogger(l), WithConfig(v))
)
go a.Serve(g)
go a.Worker(g)
a.Wait()
globalContext := global.Context()
app := newApp(globalContext, WithLogger(l), WithConfig(v))
go app.Serve(globalContext)
go app.Worker(globalContext)
app.Wait()
}
func newLogger(v *viper.Viper) *zap.Logger {
options := []logger.Option{
logger.WithLevel(v.GetString(cfgLoggerLevel)),
logger.WithTraceLevel(v.GetString(cfgLoggerTraceLevel)),
logger.WithFormat(v.GetString(cfgLoggerFormat)),
logger.WithSamplingInitial(v.GetInt(cfgLoggerSamplingInitial)),
logger.WithSamplingThereafter(v.GetInt(cfgLoggerSamplingThereafter)),
logger.WithAppName(v.GetString(cfgApplicationName)),
logger.WithAppVersion(v.GetString(cfgApplicationVersion)),
}
if v.GetBool(cfgLoggerNoCaller) {
options = append(options, logger.WithoutCaller())
}
if v.GetBool(cfgLoggerNoDisclaimer) {
options = append(options, logger.WithoutDisclaimer())
}
l, err := logger.New(options...)
if err != nil {
panic(err)
}
return l
}