From ef6c37c20b0614f0499ce37a2a0232704e51c1c3 Mon Sep 17 00:00:00 2001 From: Elara Musayelyan Date: Tue, 24 Aug 2021 08:54:08 -0700 Subject: [PATCH] Add config defaults and run go fmt --- config.go | 47 +++++++++++++++++++++++++++++++++++++++++++++++ go.mod | 4 ++-- go.sum | 4 ++++ main.go | 21 --------------------- music.go | 4 ++-- 5 files changed, 55 insertions(+), 25 deletions(-) create mode 100644 config.go diff --git a/config.go b/config.go new file mode 100644 index 0000000..5a3bf22 --- /dev/null +++ b/config.go @@ -0,0 +1,47 @@ +package main + +import ( + "os" + "strings" + + "github.com/rs/zerolog" + "github.com/rs/zerolog/log" + "github.com/spf13/viper" +) + +func init() { + // Set up logger + log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr}) + + // Set config settings + setCfgDefaults() + viper.AddConfigPath("$HOME/.cmonfig") + viper.AddConfigPath("/etoc") + viper.SetConfigName("itd") + viper.SetConfigType("toml") + viper.WatchConfig() + viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_")) + viper.SetEnvPrefix("itd") + // Ignore error because defaults set + viper.ReadInConfig() + viper.AutomaticEnv() +} + +func setCfgDefaults() { + viper.SetDefault("cfg.version", 2) + + viper.SetDefault("socket.path", "/tmp/itd/socket") + + viper.SetDefault("conn.reconnect", true) + + viper.SetDefault("on.connect.notify", true) + + viper.SetDefault("on.reconnect.notify", true) + viper.SetDefault("on.reconnect.setTime", true) + + viper.SetDefault("notifs.ignore.sender", []string{}) + viper.SetDefault("notifs.ignore.summary", []string{"InfiniTime"}) + viper.SetDefault("notifs.ignore.body", []string{}) + + viper.SetDefault("music.vol.interval", 5) +} diff --git a/go.mod b/go.mod index aaaeb37..568ea5e 100644 --- a/go.mod +++ b/go.mod @@ -19,7 +19,7 @@ require ( github.com/spf13/cast v1.4.1 // indirect github.com/spf13/cobra v1.2.1 github.com/spf13/viper v1.8.1 - go.arsenm.dev/infinitime v0.0.0-20210822201216-955384489609 - golang.org/x/sys v0.0.0-20210820121016-41cdb8703e55 // indirect + go.arsenm.dev/infinitime v0.0.0-20210823171603-8648afeebf08 + golang.org/x/sys v0.0.0-20210823070655-63515b42dcdf // indirect golang.org/x/text v0.3.7 // indirect ) diff --git a/go.sum b/go.sum index 6d2bc79..7da4862 100644 --- a/go.sum +++ b/go.sum @@ -289,6 +289,8 @@ github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9dec github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= go.arsenm.dev/infinitime v0.0.0-20210822201216-955384489609 h1:QH7hsVjulEs1OP8lcQ7EfVy2UO/rtwRsxUo3ylde83E= go.arsenm.dev/infinitime v0.0.0-20210822201216-955384489609/go.mod h1:gaepaueUz4J5FfxuV19B4w5pi+V3mD0LTef50ryxr/Q= +go.arsenm.dev/infinitime v0.0.0-20210823171603-8648afeebf08 h1:eh/ZfShWAYhi3UR6nrX+5mORDvN58A1T+NHtYoQeFC4= +go.arsenm.dev/infinitime v0.0.0-20210823171603-8648afeebf08/go.mod h1:gaepaueUz4J5FfxuV19B4w5pi+V3mD0LTef50ryxr/Q= go.etcd.io/etcd/api/v3 v3.5.0/go.mod h1:cbVKeC6lCfl7j/8jBhAK6aIYO9XOjdptoxU/nLQcPvs= go.etcd.io/etcd/client/pkg/v3 v3.5.0/go.mod h1:IJHfcCEKxYu1Os13ZdwCwIUTUVGYTSAM3YSwc9/Ac1g= go.etcd.io/etcd/client/v2 v2.305.0/go.mod h1:h9puh54ZTgAKtEbut2oe9P4L/oqKCVB6xsXlzd7alYQ= @@ -451,6 +453,8 @@ golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210820121016-41cdb8703e55 h1:rw6UNGRMfarCepjI8qOepea/SXwIBVfTKjztZ5gBbq4= golang.org/x/sys v0.0.0-20210820121016-41cdb8703e55/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210823070655-63515b42dcdf h1:2ucpDCmfkl8Bd/FsLtiD653Wf96cW37s+iGx93zsu4k= +golang.org/x/sys v0.0.0-20210823070655-63515b42dcdf/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= diff --git a/main.go b/main.go index 93f212c..c43ee25 100644 --- a/main.go +++ b/main.go @@ -19,11 +19,8 @@ package main import ( - "os" - "strings" "time" - "github.com/rs/zerolog" "github.com/rs/zerolog/log" "github.com/spf13/viper" "go.arsenm.dev/infinitime" @@ -31,24 +28,6 @@ import ( var firmwareUpdating = false -func init() { - // Set up logger - log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr}) - - // Set config settings - viper.AddConfigPath("$HOME/.config") - viper.AddConfigPath("/etc") - viper.SetConfigName("itd") - viper.SetConfigType("toml") - viper.WatchConfig() - viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_")) - viper.SetEnvPrefix("itd") - if err := viper.ReadInConfig(); err != nil { - log.Warn().Err(err).Msg("Could not read in config") - } - viper.AutomaticEnv() -} - func main() { if viper.GetInt("cfg.version") != 2 { log.Fatal().Msg("Please update your config to the newest format, only v2 configs supported.") diff --git a/music.go b/music.go index be2dfde..7dac7d9 100644 --- a/music.go +++ b/music.go @@ -19,10 +19,10 @@ package main import ( - "go.arsenm.dev/infinitime" - "go.arsenm.dev/infinitime/pkg/player" "github.com/rs/zerolog/log" "github.com/spf13/viper" + "go.arsenm.dev/infinitime" + "go.arsenm.dev/infinitime/pkg/player" ) func initMusicCtrl(dev *infinitime.Device) error {