github.com/lyraproj/hiera@v1.0.0-rc4/api/coerce.go (about) 1 package api 2 3 import ( 4 "github.com/lyraproj/dgo/dgo" 5 "github.com/lyraproj/dgo/vf" 6 "github.com/tada/catch" 7 ) 8 9 // ToMap coerces the given interface{} argument to a dgo.Map and returns it. A panic 10 // is raised if the argument cannot be coerced into a map. 11 func ToMap(argName string, vi interface{}) dgo.Map { 12 value := vf.Value(vi) 13 if vf.Nil != value { 14 if m, ok := value.(dgo.Map); ok { 15 return m 16 } 17 panic(catch.Error(`%s does not represent a map`, argName)) 18 } 19 return vf.Map() 20 }