flipped-aurora/gin-vue-admin · error
[filepath:%s]读取模版文件失败!
Error message
[filepath:%s]读取模版文件失败!
What it means
getTemplateStr parses the function template at <Root>/<Server>/resource/function/<t>.tpl before rendering auto-function code; a read/parse failure is wrapped as '[filepath:%s]读取模版文件失败!'. Called by GetApiAndServer and addTemplateToFile when generating auto-function (low-code function) assets.
Source
Thrown at server/service/system/auto_code_template.go:279
return nil, err
}
serverStr, err := s.getTemplateStr("server.go", info)
if err != nil {
return nil, err
}
jsStr, err := s.getTemplateStr("api.js", info)
if err != nil {
return nil, err
}
return map[string]string{"api": apiStr, "server": serverStr, "js": jsStr}, nil
}
func (s *autoCodeTemplate) getTemplateStr(t string, info request.AutoFunc) (string, error) {
tempPath := filepath.Join(global.GVA_CONFIG.AutoCode.Root, global.GVA_CONFIG.AutoCode.Server, "resource", "function", t+".tpl")
files, err := template.New(filepath.Base(tempPath)).Funcs(autocode.GetTemplateFuncMap()).ParseFiles(tempPath)
if err != nil {
return "", errors.Wrapf(err, "[filepath:%s]读取模版文件失败!", tempPath)
}
var builder strings.Builder
err = files.Execute(&builder, info)
if err != nil {
fmt.Println(err.Error())
return "", errors.Wrapf(err, "[filpath:%s]生成文件失败!", tempPath)
}
return builder.String(), nil
}
func (s *autoCodeTemplate) addTemplateToAst(t string, info request.AutoFunc) error {
if !isSafeFileName(info.HumpPackageName) {
return fmt.Errorf("文件名包含非法字符,拒绝写入")
}
tPath := filepath.Join(global.GVA_CONFIG.AutoCode.Root, global.GVA_CONFIG.AutoCode.Server, "router", info.Package, info.HumpPackageName+".go")
funcName := fmt.Sprintf("Init%sRouter", info.StructName)
routerStr := "RouterWithoutAuth"View on GitHub (pinned to 3136500ef3)
Solutions
- Confirm the file <filepath> printed in the error exists (ls); restore it from server/resource/function in the repository.
- Check config.yaml AutoCode.Root and AutoCode.Server values resolve to the server directory containing resource/function.
- Validate the .tpl template syntax; revert recent edits with unbalanced {{if}}/{{end}} or bad pipelines.
Example fix
// config.yaml before autoCode: root: "" # wrong // after autoCode: root: "." # resolves to server dir with resource/function
Defensive patterns
Strategy: validation
Validate before calling
tempPath := filepath.Join(global.GVA_CONFIG.AutoCode.Root, global.GVA_CONFIG.AutoCode.Server, "resource", "function", t+".tpl")
if _, err := os.Stat(tempPath); os.IsNotExist(err) {
return fmt.Errorf("function template missing: %s", tempPath)
} Try / catch
str, err := svc.getTemplateStr(t, info)
if err != nil && strings.Contains(err.Error(), "读取模版文件失败") {
log.Printf("restore .tpl under resource/function: %v", err)
return err
} Prevention
- Verify AutoCode.Root/AutoCode.Server in config.yaml on every deployment.
- Include resource/function templates in build/packaging artifacts.
- Validate custom .tpl syntax before deploying.
When it happens
Trigger: AutoFunc generation when: the function .tpl file does not exist under resource/function (missing resource files or wrong AutoCode.Root/Server config), file unreadable (permissions), or the .tpl has invalid template syntax for ParseFiles.
Common situations: Deployed binary shipped without the resource/function directory; config.yaml autoCode.root pointing to a path that differs between dev and deployment; custom function template with unbalanced {{ }} actions.
Related errors
AI-assisted analysis of flipped-aurora/gin-vue-admin@3136500ef3 (2026-08-31).
Data as JSON: /api/errors/0962f87e19e84d15.
Report an issue: GitHub.