From c6f0dd90b74156d2b2140e6183d11bfc5bb70c3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niklas=20D=C3=B6rfler?= Date: Sun, 16 Jan 2022 20:23:48 +0100 Subject: [PATCH] Add config defaults + sample config --- .github/workflows/release.yml | 2 +- config.sample.yaml | 16 ++++++++++++++++ server.go | 8 +++++++- 3 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 config.sample.yaml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 82250cb..e902822 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -32,4 +32,4 @@ jobs: goarch: ${{ matrix.goarch }} ldflags: "-X 'main.BuildTime=${{ steps.date.outputs.date }}' -X 'main.BuildVersion=${{ github.ref_name }}'" binary_name: "weather-exporter" - extra_files: README.md LICENSE + extra_files: README.md LICENSE config.sample.yaml diff --git a/config.sample.yaml b/config.sample.yaml new file mode 100644 index 0000000..222eca5 --- /dev/null +++ b/config.sample.yaml @@ -0,0 +1,16 @@ +webserverPort: 8080 + +jsonExporter: + enabled: true + +prometheusExporter: + enabled: true + +influxDbExporter: + enabled: false + server: 1.2.3.4 + port: 8086 + user: user + password: password + database: database + measurement: measurement diff --git a/server.go b/server.go index f31c1af..e73fe6b 100644 --- a/server.go +++ b/server.go @@ -37,8 +37,14 @@ func loadConfig() { viper.SetConfigName("config") viper.AddConfigPath(".") + viper.SetDefault("webserverPort", 8080) + viper.SetDefault("loglevel", "info") + viper.SetDefault("jsonExporter", map[string]interface{}{"enabled": true}) + viper.SetDefault("prometheusExporter", map[string]interface{}{"enabled": true}) + viper.SetDefault("influxDbExporter", map[string]interface{}{"enabled": false}) + if err := viper.ReadInConfig(); err != nil { - log.Fatalf("Error reading config file, %s", err) + log.Warnf("Error reading config file, using default values. %s", err) } err := viper.Unmarshal(&config) if err != nil {