feat(goctl): Support gateway sample generation (#3049)

This commit is contained in:
anqiansong
2023-03-29 17:06:23 +08:00
committed by GitHub
parent 95b85336d6
commit 1904af2323
32 changed files with 1399 additions and 513 deletions

View File

@@ -4,6 +4,7 @@ import (
"bytes"
goformat "go/format"
"io/ioutil"
"regexp"
"text/template"
"github.com/zeromicro/go-zero/tools/goctl/internal/errorx"
@@ -77,3 +78,18 @@ func (t *DefaultTemplate) Execute(data any) (*bytes.Buffer, error) {
buf.Write(formatOutput)
return buf, nil
}
// IsTemplateVariable returns true if the text is a template variable.
// The text must start with a dot and be a valid template.
func IsTemplateVariable(text string) bool {
match, _ := regexp.MatchString(`(?m)^{{(\.\w+)+}}$`, text)
return match
}
// TemplateVariable returns the variable name of the template.
func TemplateVariable(text string) string {
if IsTemplateVariable(text) {
return text[3 : len(text)-2]
}
return ""
}