aboutsummaryrefslogtreecommitdiff
path: root/pkg/config/body.go
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--pkg/config/body.go35
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...)}}
+}