forked from project-flogo/contrib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
integer.go
36 lines (29 loc) · 801 Bytes
/
integer.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package string
import (
"fmt"
"github.com/project-flogo/core/data/coerce"
"strconv"
"github.com/project-flogo/core/data"
"github.com/project-flogo/core/data/expression/function"
)
func init() {
_ = function.Register(&fnInteger{})
}
type fnInteger struct {
}
// Name returns the name of the function
func (fnInteger) Name() string {
return "integer"
}
// Sig returns the function signature
func (fnInteger) Sig() (paramTypes []data.Type, isVariadic bool) {
return []data.Type{data.TypeString}, false
}
// Eval fnInteger the function
func (fnInteger) Eval(params ...interface{}) (interface{}, error) {
s1, err := coerce.ToString(params[0])
if err != nil {
return nil, fmt.Errorf("string.integer function first parameter [%+v] must be string", params[0])
}
return strconv.Atoi(s1)
}