package libs
import (
"bytes"
"net/url"
"sort"
)
type kv struct {
k string
v string
}
type KeyValue struct {
u url.Values
s []kv
}
func NewKeyValue() *KeyValue {
return &KeyValue{
u: make(map[string][]string),
s: make([]val, 0, 2),
}
}
// Get gets the first value associated with the given key.
// If there are no values associated with the key, Get returns
// the empty string. To access multiple values, use the map
// directly.
func (s *KeyValue) Get(key string) string {
vs := s.u[key]
if len(vs) == 0 {
return ""
}
return vs[0]
}
// Set sets the key to value. It replaces any existing
func (s *KeyValue) Set(key, value string) *Values {
s.u[key] = []string{value}
s.s = append(s.s, kv{k: key, v: value})
return s
}
//Encode 参数编号返回编码后的字符串
func (s *KeyValue) Encode() string {
return s.u.Encode()
}
//Sort 对参数进行参数
func (s *KeyValue) Sort() *Values {
sort.Slice(s.s,
golang KeyValue
最新推荐文章于 2023-02-15 09:29:09 发布