diff options
Diffstat (limited to 'common.go')
-rw-r--r-- | common.go | 24 |
1 files changed, 24 insertions, 0 deletions
@@ -139,3 +139,27 @@ func setTime(m *Message, param string, t time.Time) { m.SetParam(param, t.UTC().Format(time.RFC3339)) } } + +func getSelect(m *Message, param string) (string, string, error) { + s := m.Param(param) + if s == "" { + return "", "", nil + } + ss := strings.SplitN(s, ":", 2) + if len(ss) != 2 || ss[0] == "" { + return "", "", ErrorInvalid{"invalid parameter: " + param + " is not a valid selector"} + } + return ss[0], ss[1], nil +} + +func setSelect(m *Message, param string, selector, query string) error { + if strings.ContainsRune(selector, ':') { + return ErrorInvalid{"invalid parameter: " + param + " is not a valid selector name"} + } + if selector == "" { + m.SetParam(param, "") + } else { + m.SetParam(param, selector+":"+query) + } + return nil +} |