feat(goctl): Support gateway sample generation (#3049)
This commit is contained in:
@@ -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 ""
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user