Files
podman/pkg/domain/utils/utils.go
Philip Dubé 522934d5cf Replace strings.SplitN with strings.Cut
Cut is a cleaner & more performant api relative to SplitN(_, _, 2) added in go 1.18

Previously applied this refactoring to buildah:
https://github.com/containers/buildah/pull/5239

Signed-off-by: Philip Dubé <philip@peerdb.io>
2024-01-11 13:50:15 +00:00

42 lines
773 B
Go

package utils
import (
"net/url"
"strings"
jsoniter "github.com/json-iterator/go"
)
var json = jsoniter.ConfigCompatibleWithStandardLibrary
// DeepCopy does a deep copy of a structure
// Error checking of parameters delegated to json engine
var DeepCopy = func(dst interface{}, src interface{}) error {
payload, err := json.Marshal(src)
if err != nil {
return err
}
err = json.Unmarshal(payload, dst)
if err != nil {
return err
}
return nil
}
func ToLibpodFilters(f url.Values) (filters []string) {
for k, v := range f {
filters = append(filters, k+"="+v[0])
}
return
}
func ToURLValues(f []string) (filters url.Values) {
filters = make(url.Values)
for _, v := range f {
key, val, _ := strings.Cut(v, "=")
filters.Add(key, val)
}
return
}