feat: add strings function

This commit is contained in:
Stephanie Hingtgen 2021-10-22 08:56:01 -06:00
parent 002143fcee
commit c097317875
No known key found for this signature in database
GPG Key ID: C38C0397CA26D3E5
2 changed files with 11 additions and 18 deletions

View File

@ -233,19 +233,14 @@ func setupClusterQueryParams(u *url.URL, o *ClusterOptions) (*ClusterOptions, er
} }
// addr can be specified as many times as needed // addr can be specified as many times as needed
addr := q.string("addr") addrs := q.strings("addr")
for addr != "" { for _, addr := range addrs {
h, p, err := net.SplitHostPort(addr) h, p, err := net.SplitHostPort(addr)
if err != nil || h == "" || p == "" { if err != nil || h == "" || p == "" {
return nil, fmt.Errorf("redis: unable to parse addr param: %s", addr) return nil, fmt.Errorf("redis: unable to parse addr param: %s", addr)
} }
o.Addrs = append(o.Addrs, net.JoinHostPort(h, p)) o.Addrs = append(o.Addrs, net.JoinHostPort(h, p))
addr = q.string("addr")
if q.err != nil {
return nil, q.err
}
} }
// any parameters left? // any parameters left?

View File

@ -301,20 +301,18 @@ type queryOptions struct {
} }
func (o *queryOptions) string(name string) string { func (o *queryOptions) string(name string) string {
if len(o.q[name]) == 0 { vs := o.q[name]
if len(vs) == 0 {
return "" return ""
} }
// get the first item from the array to return delete(o.q, name) // enable detection of unknown parameters
// and remove it so it isn't processed again return vs[len(vs)-1]
param := o.q[name][0] }
o.q[name] = o.q[name][1:]
// remove the key to enable detection of unknown params func (o *queryOptions) strings(name string) []string {
if len(o.q[name]) == 0 { vs := o.q[name]
delete(o.q, name) delete(o.q, name)
} return vs
return param
} }
func (o *queryOptions) int(name string) int { func (o *queryOptions) int(name string) int {