feat: gen plugin file with hrp version

This commit is contained in:
debugtalk
2022-05-28 09:40:49 +08:00
parent 7d1eec1412
commit f6af3ad12a
3 changed files with 16 additions and 7 deletions
+6 -1
View File
@@ -14,9 +14,11 @@ import (
"text/template" "text/template"
"github.com/httprunner/funplugin/shared" "github.com/httprunner/funplugin/shared"
"github.com/httprunner/httprunner/v4/hrp/internal/builtin"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
"github.com/httprunner/httprunner/v4/hrp/internal/builtin"
"github.com/httprunner/httprunner/v4/hrp/internal/version"
) )
const ( const (
@@ -36,6 +38,7 @@ var pyTemplate string
var goTemplate string var goTemplate string
type TemplateContent struct { type TemplateContent struct {
Version string // hrp version
Fun string // funplugin package Fun string // funplugin package
Regexps *Regexps // match import/function Regexps *Regexps // match import/function
Imports []string // python/go import Imports []string // python/go import
@@ -178,6 +181,7 @@ func (t *TemplateContent) genDebugTalk(path string, templ string) error {
// buildGo builds debugtalk.go to debugtalk.bin // buildGo builds debugtalk.go to debugtalk.bin
func buildGo(path string, output string) error { func buildGo(path string, output string) error {
templateContent := &TemplateContent{ templateContent := &TemplateContent{
Version: version.VERSION,
Fun: fungo, Fun: fungo,
Regexps: &Regexps{ Regexps: &Regexps{
Import: regexp.MustCompile(regexGoImport), Import: regexp.MustCompile(regexGoImport),
@@ -248,6 +252,7 @@ func buildGo(path string, output string) error {
// buildPy completes funppy information in debugtalk.py // buildPy completes funppy information in debugtalk.py
func buildPy(path string, output string) error { func buildPy(path string, output string) error {
templateContent := &TemplateContent{ templateContent := &TemplateContent{
Version: version.VERSION,
Fun: funppy, Fun: funppy,
Regexps: &Regexps{ Regexps: &Regexps{
FunctionName: regexp.MustCompile(regexPythonFunctionName), FunctionName: regexp.MustCompile(regexPythonFunctionName),
@@ -9,8 +9,9 @@ import (
{{ range $function := .Functions }} {{ range $function := .Functions }}
{{ $function }} {{ $function }}
{{ end }} {{ end }}
func main() { func main() {
{{- range $idx, $functionName := .FunctionNames }} {{- range $functionName := .FunctionNames }}
fungo.Register("{{ $functionName }}", {{ $functionName }}) fungo.Register("{{ $functionName }}", {{ $functionName }})
{{- end }} {{- end }}
fungo.Serve() fungo.Serve()
@@ -1,13 +1,16 @@
{{- range $import := .Imports }} # NOTE: Generated By hrp {{ .Version }}, DO NOT EDIT!
{{ range $import := .Imports }}
{{- $import}} {{- $import}}
{{ end }} {{ end }}
{{ range $fromImport := .FromImports }} {{ range $fromImport := .FromImports }}
{{- $fromImport}} {{- $fromImport}}
{{ end }} {{ end }}
{{ range $function := .Functions }}
{{ $function }}
{{ range $function := .Functions }}
{{- $function }}
{{ end }} {{ end }}
if __name__ == "__main__": if __name__ == "__main__":
{{- range $functionName := .FunctionNames }} {{- range $functionName := .FunctionNames }}
funppy.register("{{ $functionName }}", {{ $functionName }}) funppy.register("{{ $functionName }}", {{ $functionName }})