mirror of
https://github.com/valyala/fasthttp.git
synced 2026-06-25 17:45:28 +03:00
Added SetUint helper to Args
This commit is contained in:
@@ -172,6 +172,18 @@ func (a *Args) GetUint(key string) (int, error) {
|
||||
return ParseUint(value)
|
||||
}
|
||||
|
||||
// SetUint sets uint value for the given key.
|
||||
func (a *Args) SetUint(key string, value int) {
|
||||
a.bufKV.key = AppendBytesStr(a.bufKV.key[:0], key)
|
||||
a.SetUintBytes(a.bufKV.key, value)
|
||||
}
|
||||
|
||||
// SetUintBytes sets uint value for the given key.
|
||||
func (a *Args) SetUintBytes(key []byte, value int) {
|
||||
a.bufKV.value = AppendUint(a.bufKV.value[:0], value)
|
||||
a.SetBytesKV(key, a.bufKV.value)
|
||||
}
|
||||
|
||||
// GetUintOrZero returns uint value for the given key.
|
||||
//
|
||||
// Zero (0) is returned on error.
|
||||
|
||||
@@ -6,6 +6,39 @@ import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestArgsUint(t *testing.T) {
|
||||
var a Args
|
||||
a.SetUint("foo", 123)
|
||||
a.SetUint("bar", 0)
|
||||
a.SetUint("aaaa", 34566)
|
||||
|
||||
expectedS := "foo=123&bar=0&aaaa=34566"
|
||||
s := string(a.AppendBytes(nil))
|
||||
if s != expectedS {
|
||||
t.Fatalf("unexpected args %q. Expecting %q", s, expectedS)
|
||||
}
|
||||
|
||||
if a.GetUintOrZero("foo") != 123 {
|
||||
t.Fatalf("unexpected arg value %d. Expecting %d", a.GetUintOrZero("foo"), 123)
|
||||
}
|
||||
if a.GetUintOrZero("bar") != 0 {
|
||||
t.Fatalf("unexpected arg value %d. Expecting %d", a.GetUintOrZero("bar"), 0)
|
||||
}
|
||||
if a.GetUintOrZero("aaaa") != 34566 {
|
||||
t.Fatalf("unexpected arg value %d. Expecting %d", a.GetUintOrZero("aaaa"), 34566)
|
||||
}
|
||||
|
||||
if string(a.Peek("foo")) != "123" {
|
||||
t.Fatalf("unexpected arg value %q. Expecting %q", a.Peek("foo"), "123")
|
||||
}
|
||||
if string(a.Peek("bar")) != "0" {
|
||||
t.Fatalf("unexpected arg value %q. Expecting %q", a.Peek("bar"), "0")
|
||||
}
|
||||
if string(a.Peek("aaaa")) != "34566" {
|
||||
t.Fatalf("unexpected arg value %q. Expecting %q", a.Peek("aaaa"), "34566")
|
||||
}
|
||||
}
|
||||
|
||||
func TestArgsCopyTo(t *testing.T) {
|
||||
var a Args
|
||||
|
||||
|
||||
Reference in New Issue
Block a user