From f36b1df369b7f5dea12e6e7c54bb3de4661ba24f Mon Sep 17 00:00:00 2001 From: kianaza Date: Sun, 7 Jul 2024 11:55:29 +0330 Subject: [PATCH] fix: fix config path name and default --- README.md | 6 +++--- setting/config.example.yaml => config.example.yaml | 0 internal/cmd/root.go | 6 +++--- internal/config/config.go | 6 +++--- 4 files changed, 9 insertions(+), 9 deletions(-) rename setting/config.example.yaml => config.example.yaml (100%) diff --git a/README.md b/README.md index 45bc8f5..94147eb 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ You can deploy and use NATS Blackbox Exporter using Docker images or by building ### 1. Using Docker Image 📫 You can use pre-built Docker images from GitHub Container Registry (GHCR): ```bash -docker run -d -p 8080:8080 --name nats-blackbox-exporter -v ./setting/config.yaml:/app/setting/config.yaml:ro ghcr.io/snapp-incubator/nats-blackbox-exporter: -settings ./setting/config.yaml +docker run -d -p 8080:8080 --name nats-blackbox-exporter -v ./setting/config.yaml:/app/setting/config.yaml:ro ghcr.io/snapp-incubator/nats-blackbox-exporter: --configPath ./setting/config.yaml ``` and then pass environment variables as needed. @@ -51,12 +51,12 @@ You can check the list of parameters with default values in the [config.example. 2. **Configuration File:** - Use a `config.yaml` file to specify configuration parameters. You can specify the path to the config file using the `-settings` flag. + Use a `config.yaml` file to specify configuration parameters. You can specify the path to the config file using the `--configPath` flag. Example usage: ```bash - ./nats-blackbox-exporter -settings /path/to/config.yaml + ./nats-blackbox-exporter --configPath /path/to/config.yaml ``` Replace `/path/to/config.yaml` with the actual path to your configuration file. diff --git a/setting/config.example.yaml b/config.example.yaml similarity index 100% rename from setting/config.example.yaml rename to config.example.yaml diff --git a/internal/cmd/root.go b/internal/cmd/root.go index 5b4d721..3c3d498 100644 --- a/internal/cmd/root.go +++ b/internal/cmd/root.go @@ -13,13 +13,13 @@ import ( // ExitFailure status code. const ExitFailure = 1 -var settingsPath string +var configPath string func Execute() { - pflag.StringVar(&settingsPath, "settings", "/opt/nats-blackbox-exporter/settings.yml", "Path to settings file") + pflag.StringVar(&configPath, "configPath", "./config.yaml", "Path to config file") pflag.Parse() - cfg := config.New(settingsPath) + cfg := config.New(configPath) logger := logger.New(cfg.Logger) diff --git a/internal/config/config.go b/internal/config/config.go index 305de67..d0e1ea4 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -31,7 +31,7 @@ type ( ) // New reads configuration with koanf. -func New(settingsPath string) Config { +func New(configPath string) Config { var instance Config k := koanf.New(".") @@ -42,8 +42,8 @@ func New(settingsPath string) Config { } // load configuration from file - if err := k.Load(file.Provider(settingsPath), yaml.Parser()); err != nil { - log.Printf("error loading config.yaml from: %s", settingsPath) + if err := k.Load(file.Provider(configPath), yaml.Parser()); err != nil { + log.Printf("error loading config.yaml from: %s", configPath) } // load environment variables