Skip to content

Commit

Permalink
add yaml config file support
Browse files Browse the repository at this point in the history
  • Loading branch information
cenkalti committed Sep 11, 2020
1 parent 0d70b69 commit 56b9dbf
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
11 changes: 10 additions & 1 deletion cmd/dalga/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ import (
"fmt"
"os"
"os/signal"
"path/filepath"
"strings"
"syscall"

"github.com/cenkalti/dalga/v3"
"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"
)
Expand Down Expand Up @@ -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
}
Expand Down
File renamed without changes.

0 comments on commit 56b9dbf

Please sign in to comment.