mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-12 02:21:29 +08:00
refactor: plugin structure
This commit is contained in:
24
parser.go
24
parser.go
@@ -11,6 +11,9 @@ import (
|
||||
"github.com/maja42/goval"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/rs/zerolog/log"
|
||||
|
||||
"github.com/httprunner/hrp/internal/builtin"
|
||||
"github.com/httprunner/hrp/plugin/common"
|
||||
)
|
||||
|
||||
func newParser() *parser {
|
||||
@@ -18,7 +21,7 @@ func newParser() *parser {
|
||||
}
|
||||
|
||||
type parser struct {
|
||||
plugin hrpPlugin // plugin is used to call functions
|
||||
plugin common.Plugin // plugin is used to call functions
|
||||
}
|
||||
|
||||
func buildURL(baseURL, stepURL string) string {
|
||||
@@ -233,6 +236,25 @@ func (p *parser) parseString(raw string, variablesMapping map[string]interface{}
|
||||
return parsedString, nil
|
||||
}
|
||||
|
||||
// callFunc calls function with arguments
|
||||
// only support return at most one result value
|
||||
func (p *parser) callFunc(funcName string, arguments ...interface{}) (interface{}, error) {
|
||||
// call with plugin function
|
||||
if p.plugin != nil && p.plugin.Has(funcName) {
|
||||
return p.plugin.Call(funcName, arguments...)
|
||||
}
|
||||
|
||||
// get builtin function
|
||||
function, ok := builtin.Functions[funcName]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("function %s is not found", funcName)
|
||||
}
|
||||
fn := reflect.ValueOf(function)
|
||||
|
||||
// call with builtin function
|
||||
return common.CallFunc(fn, arguments...)
|
||||
}
|
||||
|
||||
// merge two variables mapping, the first variables have higher priority
|
||||
func mergeVariables(variables, overriddenVariables map[string]interface{}) map[string]interface{} {
|
||||
if overriddenVariables == nil {
|
||||
|
||||
Reference in New Issue
Block a user