From 9ca364d8753a5f2c7529c5b3dd7178bfd51effc6 Mon Sep 17 00:00:00 2001 From: clsr Date: Fri, 25 Aug 2017 17:04:42 +0200 Subject: Add support for the draft/cnp-select "select" request/response parameter --- common.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'common.go') diff --git a/common.go b/common.go index e6173b0..310da86 100644 --- a/common.go +++ b/common.go @@ -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 +} -- cgit