mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-15 20:38:44 +08:00
feat: call function
This commit is contained in:
26
parser.go
26
parser.go
@@ -7,6 +7,8 @@ import (
|
||||
"reflect"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/httprunner/httpboomer/builtin"
|
||||
)
|
||||
|
||||
func parseStep(step IStep, config *TConfig) *TStep {
|
||||
@@ -166,3 +168,27 @@ func mergeVariables(variables, overriddenVariables map[string]interface{}) map[s
|
||||
}
|
||||
return mergedVariables
|
||||
}
|
||||
|
||||
func callFunction(funcName string, params []interface{}) (interface{}, error) {
|
||||
function, ok := builtin.FunctionsMap[funcName]
|
||||
if !ok {
|
||||
// function not found
|
||||
return nil, fmt.Errorf("function %s is not found", funcName)
|
||||
}
|
||||
|
||||
funcValue := reflect.ValueOf(function)
|
||||
if funcValue.Kind() != reflect.Func {
|
||||
// function not valid
|
||||
return nil, fmt.Errorf("function %s is invalid", funcName)
|
||||
}
|
||||
|
||||
paramsValue := make([]reflect.Value, len(params))
|
||||
for index, param := range params {
|
||||
paramsValue[index] = reflect.ValueOf(param)
|
||||
}
|
||||
|
||||
log.Printf("[callFunction] function: %v, params: %v", funcName, params)
|
||||
result := funcValue.Call(paramsValue)
|
||||
log.Printf("[callFunction] result: %v", result)
|
||||
return result, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user