Skip to content

Commit

Permalink
Allow passing config file path as a flag
Browse files Browse the repository at this point in the history
  • Loading branch information
cycneuramus committed Mar 13, 2024
1 parent 981e9df commit 99be3d8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ To start the DNS failover mechanism, simply run the program:
./cloudflare-dns-failover
```

This assumes that `config.yml` exists in the working directory. You can, however, pass its path as a flag:

```bash
./cloudflare-dns-failover -c /path/to/config.yml
```

The program executes in an infinite loop, checking the availability of the servers at the specified interval and updating the DNS record as needed.

To maintain continuous operation, ensure that the program is running in a stable environment (e.g. as a `systemd` service or perhaps even as an orchestrated `exec` job in a [Nomad](https://www.nomadproject.io/) cluster).
13 changes: 11 additions & 2 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"fmt"

"github.com/spf13/pflag"
"github.com/spf13/viper"
)

Expand All @@ -20,8 +21,16 @@ type Record struct {
}

func parseConfig() (Config, error) {
viper.SetConfigName("config")
viper.AddConfigPath(".")
var configPath string
pflag.StringVarP(&configPath, "config", "c", "", "Path to config file")
pflag.Parse()

if configPath != "" {
viper.SetConfigFile(configPath)
} else {
viper.SetConfigName("config")
viper.AddConfigPath(".")
}

var cfg Config

Expand Down

0 comments on commit 99be3d8

Please sign in to comment.