diff options
| author | Jeff Halter <868228+jhalter@users.noreply.github.com> | 2022-06-06 20:12:16 -0700 |
|---|---|---|
| committer | Jeff Halter <868228+jhalter@users.noreply.github.com> | 2022-06-06 20:12:16 -0700 |
| commit | 18a8614d8008ab352deb04ac3023a12eb4c59f76 (patch) | |
| tree | 5b26504d522613a88b606630963ceaaae68ac525 /cmd | |
| parent | dd7aadfa4e0b3f0274a5dd86fd5ebf73ad80b2d2 (diff) | |
Handle both possible brew install paths
Diffstat (limited to 'cmd')
| -rw-r--r-- | cmd/mobius-hotline-server/main.go | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/cmd/mobius-hotline-server/main.go b/cmd/mobius-hotline-server/main.go index 285f67b..f18ae9d 100644 --- a/cmd/mobius-hotline-server/main.go +++ b/cmd/mobius-hotline-server/main.go @@ -9,12 +9,12 @@ import ( "go.uber.org/zap/zapcore" "math/rand" "os" + "runtime" "time" ) const ( - defaultConfigPath = "/usr/local/var/mobius/config/" // matches Homebrew default config location - defaultPort = 5500 + defaultPort = 5500 ) func main() { @@ -23,7 +23,7 @@ func main() { ctx, cancelRoot := context.WithCancel(context.Background()) basePort := flag.Int("bind", defaultPort, "Bind address and port") - configDir := flag.String("config", defaultConfigPath, "Path to config root") + configDir := flag.String("config", defaultConfigPath(), "Path to config root") version := flag.Bool("version", false, "print version and exit") logLevel := flag.String("log-level", "info", "Log level") flag.Parse() @@ -77,3 +77,22 @@ var zapLogLevel = map[string]zapcore.Level{ "warn": zap.WarnLevel, "error": zap.ErrorLevel, } + +func defaultConfigPath() (cfgPath string) { + switch runtime.GOOS { + case "windows": + cfgPath = "config" + case "darwin": + if _, err := os.Stat("/usr/local/var/mobius/config/"); err == nil { + cfgPath = "/usr/local/var/mobius/config/" + } else if _, err := os.Stat("/opt/homebrew/var/mobius/config"); err == nil { + cfgPath = "/opt/homebrew/var/mobius/config/" + } + case "linux": + cfgPath = "/usr/local/var/mobius/config/" + default: + fmt.Printf("unsupported OS") + } + + return cfgPath +} |