MCPcopy Index your code
hub / github.com/jetify-com/devbox / appendQueryString

Function appendQueryString

nix/flake/flakeref.go:554–573  ·  view source on GitHub ↗

appendQueryString builds a URL query string from a list of key-value string pairs, omitting any keys with empty values.

(query url.Values, keyval ...string)

Source from the content-addressed store, hash-verified

552// appendQueryString builds a URL query string from a list of key-value string
553// pairs, omitting any keys with empty values.
554func appendQueryString(query url.Values, keyval ...string) string {
555 if len(keyval)%2 != 0 {
556 panic("appendQueryString: odd number of key-value pairs")
557 }
558
559 appended := make(url.Values, len(query)+len(keyval)/2)
560 for k, vals := range query {
561 v := cmp.Or(vals...)
562 if v != "" {
563 appended.Set(k, v)
564 }
565 }
566 for i := 0; i < len(keyval); i += 2 {
567 k, v := keyval[i], keyval[i+1]
568 if v != "" {
569 appended.Set(k, v)
570 }
571 }
572 return appended.Encode()
573}
574
575// itoaOmitZero returns an empty string if i == 0, otherwise it formats i as a
576// string in base-10.

Callers 2

StringMethod · 0.85
TestBuildQueryStringFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestBuildQueryStringFunction · 0.68