rewrite gnmiPathToXPath to use strings.Builder and include origin
@@ -223,20 +223,27 @@ func gnmiPathToXPath(p *gnmi.Path) string {
if p == nil {
return ""
}
- pathElems := make([]string, 0, len(p.GetElem()))
- for _, pe := range p.GetElem() {
- elem := ""
- if pe.GetName() != "" {
- elem += pe.GetName()
- }
- if pe.GetKey() != nil {
+ sb := strings.Builder{}
+ if p.Origin != "" {
+ sb.WriteString(p.Origin)
+ sb.WriteString(":")
+ }
+ elems := p.GetElem()
+ numElems := len(elems)
+ for i, pe := range elems {
+ sb.WriteString(pe.GetName())
for k, v := range pe.GetKey() {
- elem += fmt.Sprintf("[%s=%s]", k, v)
+ sb.WriteString("[")
+ sb.WriteString(k)
+ sb.WriteString("=")
+ sb.WriteString(v)
+ sb.WriteString("]")
}
+ if i+1 != numElems {
+ sb.WriteString("/")
}
- pathElems = append(pathElems, elem)
}
- return strings.Join(pathElems, "/")
+ return sb.String()
}
func loadCerts(tlscfg *tls.Config) error {
tlsCert := viper.GetString("tls-cert")
