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