diff options
author | clsr <clsr@clsr.net> | 2017-08-25 17:04:42 +0200 |
---|---|---|
committer | clsr <clsr@clsr.net> | 2017-08-25 17:04:44 +0200 |
commit | 9ca364d8753a5f2c7529c5b3dd7178bfd51effc6 (patch) | |
tree | dc5ab072ffbbd37da910d440e05b5bc56dc3f6da /common.go | |
parent | ba217ddeef9c6cd502a6f150bf59cf3ce329cc61 (diff) | |
download | cnp-go-9ca364d8753a5f2c7529c5b3dd7178bfd51effc6.tar.gz cnp-go-9ca364d8753a5f2c7529c5b3dd7178bfd51effc6.zip |
Add support for the draft/cnp-select "select" request/response parameterv0.1.2
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 +} |