Add new options for linters, fix logs view for Windows
This commit is contained in:
parent
000e3d9af9
commit
dd001963b2
@ -4,6 +4,8 @@ linters:
|
||||
enable-all: true
|
||||
disable:
|
||||
- gochecknoglobals
|
||||
- funlen
|
||||
- wsl
|
||||
linters-settings:
|
||||
lll:
|
||||
line-length: 120
|
||||
@ -13,3 +15,6 @@ issues:
|
||||
- path: "exported.go"
|
||||
linters:
|
||||
- dupl
|
||||
- linters:
|
||||
- wsl
|
||||
text: "declarations should never be cuddled"
|
@ -43,18 +43,28 @@ func (c *Context) readConfig() {
|
||||
defer fh.Close()
|
||||
|
||||
decoder := json.NewDecoder(fh)
|
||||
|
||||
err = decoder.Decode(&c.Config)
|
||||
if err != nil {
|
||||
dlog.Fatal().Err(err).Msg("Ошибка декодирования конфигурации")
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Context) setLogNoColor() bool {
|
||||
return runtime.GOOS == "windows"
|
||||
}
|
||||
|
||||
// Init is an initialization function for core context
|
||||
// Without these parts of the application we can't start at all
|
||||
func (c *Context) Init() {
|
||||
c.initFlagger()
|
||||
|
||||
c.Logger = zerolog.New(zerolog.ConsoleWriter{Out: os.Stdout}).With().Timestamp().Logger()
|
||||
c.Logger = zerolog.New(
|
||||
zerolog.ConsoleWriter{
|
||||
Out: os.Stdout,
|
||||
NoColor: c.setLogNoColor(),
|
||||
},
|
||||
).With().Timestamp().Logger()
|
||||
c.Logger = c.Logger.Hook(zerolog.HookFunc(c.getMemoryUsage))
|
||||
|
||||
dlog = c.Logger.With().Str("модуль", "context").Logger()
|
||||
@ -62,6 +72,7 @@ func (c *Context) Init() {
|
||||
|
||||
func (c *Context) InitConfig() {
|
||||
configPath := configdir.LocalConfig("uploader_tools")
|
||||
|
||||
err := configdir.MakePath(configPath)
|
||||
if err != nil {
|
||||
dlog.Fatal().Err(err).Str("директория с конфигурационным файлом", configPath).
|
||||
@ -91,9 +102,11 @@ func (c *Context) SaveConfig() {
|
||||
if err != nil {
|
||||
dlog.Fatal().Err(err).Msg("Не удалось создать файл конфигурации")
|
||||
}
|
||||
|
||||
defer fh.Close()
|
||||
|
||||
encoder := json.NewEncoder(fh)
|
||||
|
||||
err = encoder.Encode(&c.Config)
|
||||
if err != nil {
|
||||
dlog.Fatal().Err(err).Msg("Не удалось записать файл конфигурации")
|
||||
|
Loading…
Reference in New Issue
Block a user