Add detailed parameter tracing + custom prefix (#18518)

* Allow per handler custom prefix.
* Add automatic parameter extraction
This commit is contained in:
Klaus Post
2023-11-26 01:32:59 -08:00
committed by GitHub
parent 11dc723324
commit ca488cce87
6 changed files with 93 additions and 9 deletions
+28
View File
@@ -19,6 +19,9 @@ package grid
import (
"errors"
"net/url"
"sort"
"strings"
"github.com/tinylib/msgp/msgp"
)
@@ -117,6 +120,31 @@ func NewMSSWith(m map[string]string) *MSS {
return &m2
}
// ToQuery constructs a URL query string from the MSS, including "?" if there are any keys.
func (m MSS) ToQuery() string {
if len(m) == 0 {
return ""
}
var buf strings.Builder
buf.WriteByte('?')
keys := make([]string, 0, len(m))
for k := range m {
keys = append(keys, k)
}
sort.Strings(keys)
for _, k := range keys {
v := m[k]
keyEscaped := url.QueryEscape(k)
if buf.Len() > 1 {
buf.WriteByte('&')
}
buf.WriteString(keyEscaped)
buf.WriteByte('=')
buf.WriteString(url.QueryEscape(v))
}
return buf.String()
}
// NewBytes returns a new Bytes.
func NewBytes() *Bytes {
b := Bytes(GetByteBuffer()[:0])