github.com/TIBCOSoftware/flogo-lib@v0.5.9/core/mapper/exprmapper/function/array/length/length.go (about) 1 package length 2 3 import ( 4 "fmt" 5 6 "github.com/TIBCOSoftware/flogo-lib/core/data" 7 "github.com/TIBCOSoftware/flogo-lib/core/mapper/exprmapper/expression/function" 8 "github.com/TIBCOSoftware/flogo-lib/logger" 9 ) 10 11 var log = logger.GetLogger("length-function") 12 13 type Length struct { 14 } 15 16 func init() { 17 function.Registry(&Length{}) 18 } 19 20 func (s *Length) GetName() string { 21 return "length" 22 } 23 24 func (s *Length) GetCategory() string { 25 return "array" 26 } 27 28 func (s *Length) Eval(arr interface{}) (int, error) { 29 log.Debugf("Return the length of array \"%v\"", arr) 30 myArr, err := data.CoerceToArray(arr) 31 if err != nil { 32 return 0, fmt.Errorf(err.Error()) 33 } 34 return len(myArr), nil 35 }