From dd001963b216faf34ee0e4ec335ef3f31150dd1e Mon Sep 17 00:00:00 2001 From: Vladimir Hodakov Date: Sat, 12 Oct 2019 23:29:51 +0400 Subject: [PATCH] Add new options for linters, fix logs view for Windows --- .golangci.yaml | 5 +++++ internal/context/context.go | 15 ++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/.golangci.yaml b/.golangci.yaml index 548b319..4dfeeda 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -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" \ No newline at end of file diff --git a/internal/context/context.go b/internal/context/context.go index 4e4805e..d6ea6e6 100644 --- a/internal/context/context.go +++ b/internal/context/context.go @@ -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("Не удалось записать файл конфигурации")