Skip to content
Snippets Groups Projects
pathHandling.go 597 B
Newer Older
  • Learn to ignore specific revisions
  • Malte Bauch's avatar
    WIP
    Malte Bauch committed
    package ubuntu
    
    import (
    	"fmt"
    
    	"github.com/openconfig/gnmi/proto/gnmi"
    )
    
    type PathFunc func(path *gnmi.Path, val *gnmi.TypedValue) error
    
    type PathMap map[string]PathFunc
    
    func (pm PathMap) Register(s string, fn PathFunc) error {
    	if _, found := pm[s]; found {
    		return fmt.Errorf("a function is already registered for path: '%s'", s)
    	}
    	pm[s] = fn
    	return nil
    }
    
    func (pm PathMap) Execute(s string) error {
    	return execute(pm, s)
    }
    
    func execute(pm PathMap, p string) error {
    	if _, found := pm[p]; found {
    		//return fn()
    	}
    	return fmt.Errorf("The given path: '%s' is not supported", p)
    }