forked from project-flogo/contrib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconcat.go
40 lines (33 loc) · 852 Bytes
/
concat.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
37
38
39
40
package string
import (
"bytes"
"fmt"
"github.com/project-flogo/core/data"
"github.com/project-flogo/core/data/coerce"
"github.com/project-flogo/core/data/expression/function"
)
func init() {
_ = function.Register(&fnConcat{})
}
type fnConcat struct {
}
func (fnConcat) Name() string {
return "concat"
}
func (fnConcat) Sig() (paramTypes []data.Type, isVariadic bool) {
return []data.Type{data.TypeString}, true
}
func (fnConcat) Eval(params ...interface{}) (interface{}, error) {
if len(params) >= 2 {
var buffer bytes.Buffer
for _, v := range params {
s, err := coerce.ToString(v)
if err != nil {
return nil, fmt.Errorf("concat function parameter [%+v] must be string.", v)
}
buffer.WriteString(s)
}
return buffer.String(), nil
}
return "", fmt.Errorf("fnConcat function must have at least two arguments")
}