diff options
author | Gabriel A. Giovanini <mail@gabrielgio.me> | 2024-05-25 23:41:01 +0200 |
---|---|---|
committer | Gabriel A. Giovanini <mail@gabrielgio.me> | 2024-05-25 23:41:40 +0200 |
commit | c06945c189c1d8ef3cedeb51e416ba0fec36368f (patch) | |
tree | e9655b29715d5bae1d3fc5f669a74f2d7bde3c4e /pkg/config/config.go | |
parent | ce911df583e384d86018e42f9548cdf33d1c1549 (diff) | |
download | cerrado-c06945c189c1d8ef3cedeb51e416ba0fec36368f.tar.gz cerrado-c06945c189c1d8ef3cedeb51e416ba0fec36368f.tar.bz2 cerrado-c06945c189c1d8ef3cedeb51e416ba0fec36368f.zip |
feat: Add utils
Diffstat (limited to 'pkg/config/config.go')
-rw-r--r-- | pkg/config/config.go | 15 |
1 files changed, 4 insertions, 11 deletions
diff --git a/pkg/config/config.go b/pkg/config/config.go index ba1614f..776c698 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -5,6 +5,7 @@ import ( "io" "strconv" + "git.gabrielgio.me/cerrado/pkg/u" "git.sr.ht/~emersion/go-scfg" ) @@ -56,9 +57,9 @@ func setScan(block scfg.Block, scan *Scan) error { } func setBool(dir *scfg.Directive, field *bool) error { - if dir != nil { - p1 := first(dir.Params) + + p1, _ := u.First(dir.Params) v, err := strconv.ParseBool(p1) if err != nil { return fmt.Errorf("Error parsing bool param of %s: %w", dir.Name, err) @@ -70,15 +71,7 @@ func setBool(dir *scfg.Directive, field *bool) error { func setString(dir *scfg.Directive, field *string) error { if dir != nil { - *field = first(dir.Params) + *field, _ = u.First(dir.Params) } return nil } - -func first[T any](v []T) T { - if len(v) == 0 { - var zero T - return zero - } - return v[0] -} |