Skip to content

Commit

Permalink
Add config defaults + sample config
Browse files Browse the repository at this point in the history
  • Loading branch information
niklasdoerfler committed Jan 16, 2022
1 parent 058cbc0 commit c6f0dd9
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
16 changes: 16 additions & 0 deletions config.sample.yaml
Original file line number Diff line number Diff line change
@@ -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
8 changes: 7 additions & 1 deletion server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit c6f0dd9

Please sign in to comment.