From 52ce77efa88209af0f09f9d57086d979cef059d4 Mon Sep 17 00:00:00 2001 From: debugtalk Date: Sat, 28 May 2022 09:40:49 +0800 Subject: [PATCH] feat: gen plugin file with hrp version --- hrp/internal/build/main.go | 11 ++++++++--- hrp/internal/build/templates/debugtalkGoTemplate | 3 ++- hrp/internal/build/templates/debugtalkPythonTemplate | 9 ++++++--- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/hrp/internal/build/main.go b/hrp/internal/build/main.go index 2c9cd28b..72848b5b 100644 --- a/hrp/internal/build/main.go +++ b/hrp/internal/build/main.go @@ -14,9 +14,11 @@ import ( "text/template" "github.com/httprunner/funplugin/shared" - "github.com/httprunner/httprunner/v4/hrp/internal/builtin" "github.com/pkg/errors" "github.com/rs/zerolog/log" + + "github.com/httprunner/httprunner/v4/hrp/internal/builtin" + "github.com/httprunner/httprunner/v4/hrp/internal/version" ) const ( @@ -36,6 +38,7 @@ var pyTemplate string var goTemplate string type TemplateContent struct { + Version string // hrp version Fun string // funplugin package Regexps *Regexps // match import/function Imports []string // python/go import @@ -178,7 +181,8 @@ func (t *TemplateContent) genDebugTalk(path string, templ string) error { // buildGo builds debugtalk.go to debugtalk.bin func buildGo(path string, output string) error { templateContent := &TemplateContent{ - Fun: fungo, + Version: version.VERSION, + Fun: fungo, Regexps: &Regexps{ Import: regexp.MustCompile(regexGoImport), Imports: regexp.MustCompile(regexGoImports), @@ -248,7 +252,8 @@ func buildGo(path string, output string) error { // buildPy completes funppy information in debugtalk.py func buildPy(path string, output string) error { templateContent := &TemplateContent{ - Fun: funppy, + Version: version.VERSION, + Fun: funppy, Regexps: &Regexps{ FunctionName: regexp.MustCompile(regexPythonFunctionName), }, diff --git a/hrp/internal/build/templates/debugtalkGoTemplate b/hrp/internal/build/templates/debugtalkGoTemplate index d6d0a95e..842eba1d 100644 --- a/hrp/internal/build/templates/debugtalkGoTemplate +++ b/hrp/internal/build/templates/debugtalkGoTemplate @@ -9,8 +9,9 @@ import ( {{ range $function := .Functions }} {{ $function }} {{ end }} + func main() { -{{- range $idx, $functionName := .FunctionNames }} +{{- range $functionName := .FunctionNames }} fungo.Register("{{ $functionName }}", {{ $functionName }}) {{- end }} fungo.Serve() diff --git a/hrp/internal/build/templates/debugtalkPythonTemplate b/hrp/internal/build/templates/debugtalkPythonTemplate index 4da17d12..dc16657a 100644 --- a/hrp/internal/build/templates/debugtalkPythonTemplate +++ b/hrp/internal/build/templates/debugtalkPythonTemplate @@ -1,13 +1,16 @@ -{{- range $import := .Imports }} +# NOTE: Generated By hrp {{ .Version }}, DO NOT EDIT! + +{{ range $import := .Imports }} {{- $import}} {{ end }} {{ range $fromImport := .FromImports }} {{- $fromImport}} {{ end }} -{{ range $function := .Functions }} -{{ $function }} +{{ range $function := .Functions }} +{{- $function }} {{ end }} + if __name__ == "__main__": {{- range $functionName := .FunctionNames }} funppy.register("{{ $functionName }}", {{ $functionName }})