summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Pointner <equinox@spreadspace.org>2017-06-29 11:13:39 +0200
committerChristian Pointner <equinox@spreadspace.org>2017-06-29 11:13:39 +0200
commitac7002b26b30251b3b3d5c610ce596e5c87eb1dc (patch)
treebda55f3c8cfa53e8ede3e1fbb727fe87cb3e6ed8 /src
parentadd warning if https is enabled but no cert/key is configured (diff)
improve config parsing for header operation
Diffstat (limited to 'src')
-rw-r--r--src/daq/s5proxy/src/s5proxy/config.go42
1 files changed, 16 insertions, 26 deletions
diff --git a/src/daq/s5proxy/src/s5proxy/config.go b/src/daq/s5proxy/src/s5proxy/config.go
index 1aa773a..10e1e7e 100644
--- a/src/daq/s5proxy/src/s5proxy/config.go
+++ b/src/daq/s5proxy/src/s5proxy/config.go
@@ -115,41 +115,31 @@ func (r *RedirectCode) UnmarshalJSON(data []byte) (err error) {
return r.fromString(string(data))
}
-type Operation uint
+type Operation string
const (
- OpAdd Operation = iota
- OpDel
- OpSet
- OpTime
+ OpAdd Operation = "add"
+ OpDel Operation = "del"
+ OpSet Operation = "set"
+ OpTime Operation = "time"
)
func (o Operation) String() string {
- switch o {
- case OpAdd:
- return "add"
- case OpDel:
- return "del"
- case OpSet:
- return "set"
- case OpTime:
- return "time"
- }
- return "unknown"
+ return string(o)
}
func (o *Operation) fromString(str string) (err error) {
- switch str {
- case "add":
- *o = OpAdd
- case "del":
- *o = OpDel
- case "set":
- *o = OpSet
- case "time":
- *o = OpTime
+ switch strings.ToLower(str) {
+ case string(OpAdd):
+ fallthrough
+ case string(OpDel):
+ fallthrough
+ case string(OpSet):
+ fallthrough
+ case string(OpTime):
+ *o = Operation(strings.ToLower(str))
default:
- return errors.New("invalid operation: '" + str + "'")
+ return fmt.Errorf("invalid operation: '"+str+"', must be one of '%s', '%s', '%s' or '%s'", OpAdd, OpDel, OpSet, OpTime)
}
return
}