2019-11-06 15:33:46 +03:00
|
|
|
package main
|
|
|
|
|
2020-11-09 16:43:23 +03:00
|
|
|
import (
|
2021-01-14 13:28:20 +03:00
|
|
|
"github.com/nspcc-dev/cdn-sdk/grace"
|
|
|
|
"github.com/nspcc-dev/cdn-sdk/logger"
|
2020-11-09 16:43:23 +03:00
|
|
|
"github.com/spf13/viper"
|
|
|
|
"go.uber.org/zap"
|
|
|
|
)
|
|
|
|
|
|
|
|
func newLogger(v *viper.Viper) *zap.Logger {
|
|
|
|
options := []logger.Option{
|
2020-11-27 18:18:53 +03:00
|
|
|
logger.WithLevel(v.GetString(cfgLoggerLevel)),
|
|
|
|
logger.WithTraceLevel(v.GetString(cfgLoggerTraceLevel)),
|
2020-11-09 16:43:23 +03:00
|
|
|
|
2020-11-27 18:18:53 +03:00
|
|
|
logger.WithFormat(v.GetString(cfgLoggerFormat)),
|
2020-11-09 16:43:23 +03:00
|
|
|
|
2020-11-27 18:18:53 +03:00
|
|
|
logger.WithSamplingInitial(v.GetInt(cfgLoggerSamplingInitial)),
|
|
|
|
logger.WithSamplingThereafter(v.GetInt(cfgLoggerSamplingThereafter)),
|
2020-11-09 16:43:23 +03:00
|
|
|
|
2020-11-27 18:18:53 +03:00
|
|
|
logger.WithAppName(v.GetString(cfgApplicationName)),
|
|
|
|
logger.WithAppVersion(v.GetString(cfgApplicationVersion)),
|
2020-11-09 16:43:23 +03:00
|
|
|
}
|
|
|
|
|
2020-11-27 18:18:53 +03:00
|
|
|
if v.GetBool(cfgLoggerNoCaller) {
|
2020-11-09 16:43:23 +03:00
|
|
|
options = append(options, logger.WithoutCaller())
|
|
|
|
}
|
|
|
|
|
2020-11-27 18:18:53 +03:00
|
|
|
if v.GetBool(cfgLoggerNoDisclaimer) {
|
2020-11-09 16:43:23 +03:00
|
|
|
options = append(options, logger.WithoutDisclaimer())
|
|
|
|
}
|
|
|
|
|
|
|
|
l, err := logger.New(options...)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return l
|
|
|
|
}
|
|
|
|
|
2019-11-06 15:33:46 +03:00
|
|
|
func main() {
|
|
|
|
var (
|
2019-12-21 13:26:14 +03:00
|
|
|
v = settings()
|
|
|
|
l = newLogger(v)
|
2020-11-09 16:43:23 +03:00
|
|
|
g = grace.Context(l)
|
2020-02-28 20:07:50 +03:00
|
|
|
|
2020-11-09 16:43:23 +03:00
|
|
|
a = newApp(g,
|
2020-03-31 11:37:10 +03:00
|
|
|
WithLogger(l),
|
|
|
|
WithConfig(v))
|
|
|
|
)
|
2019-11-06 15:33:46 +03:00
|
|
|
|
2020-03-31 11:37:10 +03:00
|
|
|
go a.Serve(g)
|
|
|
|
go a.Worker(g)
|
2019-12-21 13:26:14 +03:00
|
|
|
|
2020-03-31 11:37:10 +03:00
|
|
|
a.Wait()
|
2019-11-06 15:33:46 +03:00
|
|
|
}
|