mirror of
https://github.com/hanzoai/traces.git
synced 2026-10-30 18:20:41 +00:00
* create and use a way to consistently clone requests Signed-off-by: Joe Elliott <[email protected]> * use content len Signed-off-by: Joe Elliott <[email protected]> * fix tests Signed-off-by: Joe Elliott <[email protected]> * standardize logging Signed-off-by: Joe Elliott <[email protected]> * cleanup Signed-off-by: Joe Elliott <[email protected]> * i love the linter Signed-off-by: Joe Elliott <[email protected]> * lint Signed-off-by: Joe Elliott <[email protected]> * prealloc builder Signed-off-by: Joe Elliott <[email protected]> * changelog Signed-off-by: Joe Elliott <[email protected]> * do what the comment says so CI passes Signed-off-by: Joe Elliott <[email protected]> * review Signed-off-by: Joe Elliott <[email protected]> * add tracing context to pipeline request Signed-off-by: Joe Elliott <[email protected]> --------- Signed-off-by: Joe Elliott <[email protected]>
43 lines
1003 B
Go
43 lines
1003 B
Go
package api
|
|
|
|
import (
|
|
"net/url"
|
|
"strings"
|
|
)
|
|
|
|
type queryBuilder struct {
|
|
builder strings.Builder
|
|
}
|
|
|
|
// newQueryBuilder creates a new queryBuilder
|
|
func newQueryBuilder(init string) *queryBuilder {
|
|
qb := &queryBuilder{
|
|
builder: strings.Builder{},
|
|
}
|
|
|
|
qb.builder.Grow(100) // pre-allocate some space. ideally the caller could indicate roughly the expected size, but starting with 100 bytes significantly outperforms 0
|
|
qb.builder.WriteString(init)
|
|
return qb
|
|
}
|
|
|
|
// addParam adds a new key/val pair to the query
|
|
// like https://cs.opensource.google/go/go/+/refs/tags/go1.22.5:src/net/url/url.go;l=972
|
|
func (qb *queryBuilder) addParam(key, value string) {
|
|
if qb.builder.Len() > 0 {
|
|
qb.builder.WriteByte('&')
|
|
}
|
|
|
|
keyStr := url.QueryEscape(key)
|
|
valueStr := url.QueryEscape(value)
|
|
|
|
qb.builder.Grow(len(keyStr) + len(valueStr) + 1)
|
|
|
|
qb.builder.WriteString(keyStr)
|
|
qb.builder.WriteByte('=')
|
|
qb.builder.WriteString(valueStr)
|
|
}
|
|
|
|
func (qb *queryBuilder) query() string {
|
|
return qb.builder.String()
|
|
}
|