diff options
author | René 'Necoro' Neumann <necoro@necoro.eu> | 2020-05-02 16:48:51 +0200 |
---|---|---|
committer | René 'Necoro' Neumann <necoro@necoro.eu> | 2020-05-02 16:48:51 +0200 |
commit | d75bbcf9a7fe589f119b103d357ffa874008ab07 (patch) | |
tree | 9f5b27e5e9c48e3d0e5acd5bf6f16f60f47b6b29 /pkg/config/body.go | |
parent | 3e219c232c0bb4a64f615c599473c959691e6319 (diff) | |
download | feed2imap-go-d75bbcf9a7fe589f119b103d357ffa874008ab07.tar.gz feed2imap-go-d75bbcf9a7fe589f119b103d357ffa874008ab07.tar.bz2 feed2imap-go-d75bbcf9a7fe589f119b103d357ffa874008ab07.zip |
Option 'body'
Diffstat (limited to '')
-rw-r--r-- | pkg/config/body.go | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/pkg/config/body.go b/pkg/config/body.go new file mode 100644 index 0000000..d9957d5 --- /dev/null +++ b/pkg/config/body.go @@ -0,0 +1,35 @@ +package config + +import ( + "fmt" + + "gopkg.in/yaml.v3" + + "github.com/Necoro/feed2imap-go/pkg/util" +) + +type Body string + +var validBody = []string{"default", "both", "content", "description"} + +func (b *Body) UnmarshalYAML(node *yaml.Node) error { + var val string + if err := node.Decode(&val); err != nil { + return err + } + + if val == "" { + val = "default" + } + + if !util.StrContains(validBody, val) { + return TypeError("line %d: Invalid value for 'body': %q", node.Line, val) + } + + *b = Body(val) + return nil +} + +func TypeError(format string, v ...interface{}) *yaml.TypeError { + return &yaml.TypeError{Errors: []string{fmt.Sprintf(format, v...)}} +} |