diff options
author | clsr <clsr@clsr.net> | 2017-09-01 16:11:42 +0200 |
---|---|---|
committer | clsr <clsr@clsr.net> | 2017-09-01 16:11:42 +0200 |
commit | 7e1f90f27d876db67158ca4787420ec30c18f86b (patch) | |
tree | 4526e5924c926af4814968a49c2dd7875fdf0dd0 /request.go | |
parent | ee431f1e85a8ee7d3c6e069c8858c671da1c2acd (diff) | |
download | cnp-go-7e1f90f27d876db67158ca4787420ec30c18f86b.tar.gz cnp-go-7e1f90f27d876db67158ca4787420ec30c18f86b.zip |
Distinguish between response length=0 and no length parameter
Response.Length returns -1 when the parameter is not present and 0
when it's set to 0.
Response.SetLength will only unset the parameter when given -1.
Diffstat (limited to 'request.go')
-rw-r--r-- | request.go | 20 |
1 files changed, 20 insertions, 0 deletions
@@ -219,6 +219,26 @@ func (r *Request) SetSelect(selector, query string) error { return setSelect(&r.Message, "select", selector, query) } +// Length gets the length request parameter (or 0 if not set or invalid). +func (r *Request) Length() int64 { + n, err := getInt(&r.Message, "length", 0) + if err != nil { + return 0 + } + return n +} + +// SetLength sets the length request parameter to n. +// +// If n is negative or zero, the parameter is unset. +func (r *Request) SetLength(n int64) { + if n <= 0 { + r.SetParam("length", "") + } else { + setInt(&r.Message, "length", n) + } +} + // Validate validates the request header intent and parameter value format // (length, name, type, if_modified, select) func (r *Request) Validate() error { |