forked from zpsean/go4api
/
call.go
58 lines (50 loc) · 1.6 KB
/
call.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
* go4api - an api testing tool written in Go
* Created by: Ping Zhu 2018
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
*/
package builtins
import (
// "fmt"
// "math/rand"
// "time"
// "strings"
"reflect"
)
func BuiltinFunctionsMapping (key string) interface{} {
//
FuncsMapping := map[string]interface{} {
"NextInt": NextInt,
"NextAlphaNumeric": NextAlphaNumeric,
"NextStringNumeric": NextStringNumeric,
"Substitute": Substitute,
"Select": Select,
"Join": Join,
"Split": Split,
"Replace": Replace,
"SubString": SubString,
"ToString": ToString,
"Length": Length,
"ToInt": ToInt,
"ToBool": ToBool,
"CurrentTimeStampString": CurrentTimeStampString,
"CurrentTimeStampUnix": CurrentTimeStampUnix,
"DayStart": DayStart,
"DayEnd": DayEnd,
"ConvertTimeToUnix": ConvertTimeToUnix,
"ConvertTimeToStr": ConvertTimeToStr,
"TimeStampUnixOffset": TimeStampUnixOffset,
}
return FuncsMapping[key]
}
func CallBuiltinFunc (funcName string, funcParams interface{}) interface{} {
f := reflect.ValueOf(BuiltinFunctionsMapping(funcName))
var in []reflect.Value
in = append(in, reflect.ValueOf(funcParams))
result := f.Call(in)
return result[0].Interface()
}