add parsePath func to support origin as a prefix of a path
@@ -31,6 +31,7 @@ import (
"syscall"
"time"
+ "github.com/google/gnxi/utils/xpath"
"github.com/karimra/gnmic/collector"
homedir "github.com/mitchellh/go-homedir"
"github.com/mitchellh/mapstructure"
@@ -540,3 +541,21 @@ func createCollectorDialOpts() []grpc.DialOption {
}
return opts
}
+
+func parsePath(p string) (*gnmi.Path, error) {
+ var origin string
+ elems := strings.Split(p, "/")
+ if len(elems) > 0 {
+ f := strings.Split(elems[0], ":")
+ if len(f) > 1 {
+ origin = f[0]
+ elems[0] = strings.Join(f[1:], ":")
+ }
+ }
+ gnmiPath, err := xpath.ToGNMIPath(strings.Join(elems, "/"))
+ if err != nil {
+ return nil, err
+ }
+ gnmiPath.Origin = origin
+ return gnmiPath, nil
+}
