From 56b9dbf872747275322c1cad700db43ed166127c Mon Sep 17 00:00:00 2001 From: Cenk Alti Date: Fri, 11 Sep 2020 15:34:17 +0300 Subject: [PATCH] add yaml config file support --- README.md | 3 ++- cmd/dalga/main.go | 11 ++++++++++- dalga.toml => config.toml | 0 3 files changed, 12 insertions(+), 2 deletions(-) rename dalga.toml => config.toml (100%) diff --git a/README.md b/README.md index 8c4071b..cd391e7 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,8 @@ or download the latest binary from [releases page](https://github.com/cenkalti/d Usage ----- -See [example config file](https://github.com/cenkalti/dalga/blob/v3/dalga.toml) for configuration options. +See [example config file](https://github.com/cenkalti/dalga/blob/v3/config.toml) for configuration options. +TOML and YAML file formats are supported. Configuration values can also be set via environment variables with `DALGA_` prefix. First, you must create the table for storing jobs: diff --git a/cmd/dalga/main.go b/cmd/dalga/main.go index 583ee41..79d6e0d 100644 --- a/cmd/dalga/main.go +++ b/cmd/dalga/main.go @@ -6,6 +6,7 @@ import ( "fmt" "os" "os/signal" + "path/filepath" "strings" "syscall" @@ -13,6 +14,7 @@ import ( "github.com/cenkalti/dalga/v3/internal/log" "github.com/knadh/koanf" "github.com/knadh/koanf/parsers/toml" + "github.com/knadh/koanf/parsers/yaml" "github.com/knadh/koanf/providers/env" "github.com/knadh/koanf/providers/file" ) @@ -84,7 +86,14 @@ func main() { func readConfig() (c dalga.Config, err error) { c = dalga.DefaultConfig k := koanf.New(".") - err = k.Load(file.Provider(*configFlag), toml.Parser()) + var parser koanf.Parser + ext := filepath.Ext(*configFlag) + if ext == ".yaml" || ext == ".yml" { + parser = yaml.Parser() + } else { + parser = toml.Parser() + } + err = k.Load(file.Provider(*configFlag), parser) if err != nil { return } diff --git a/dalga.toml b/config.toml similarity index 100% rename from dalga.toml rename to config.toml