flipped-aurora/gin-vue-admin · error

[filpath: ]非法模版后缀!

Error message

[filpath:%s]非法模版后缀!

What it means

Inside <templateDir>/server, any non-directory entry must end with .tpl. If a file has another extension, templates() aborts with errors.Errorf("[filpath:%s]非法模版后缀!"). The generator treats resource templates as strict .tpl assets, so stray files break the whole generation run.

Solutions

  1. Open the path shown in the error and either delete the offending file or rename it to <name>.tpl.
  2. Move non-template documentation out of the server template folder.
  3. Delete editor/OS temp files (foo~, *.swp, .bak) before generating.
  4. Keep custom template files always with the .tpl extension so the walker accepts them.

Example fix

// before
resource/package/server/notes.md
// after
mv resource/package/server/notes.md docs/  # or rename to notes.md.tpl if it is a template
Defensive patterns

Strategy: validation

Validate before calling

entries, _ := os.ReadDir(filepath.Join(templateDir, "server"))
for _, e := range entries {
    if e.IsDir() || e.Name() == ".DS_Store" {
        continue
    }
    if filepath.Ext(e.Name()) != ".tpl" {
        return fmt.Errorf("server 层存在非 .tpl 文件: %s", e.Name())
    }
}

Type guard

func isTpl(name string) bool { return filepath.Ext(name) == ".tpl" }

Try / catch

if err := runGeneration(); err != nil {
    var pathErr interface{ Error() string }
    if strings.Contains(err.Error(), "非法模版后缀") {
        return fmt.Errorf("模板目录混入非 .tpl 文件,按报错路径清理后重试: %w", err)
    }
    _ = pathErr
    return err
}

Prevention

When it happens

Trigger: A file that is not a .tpl (e.g. README.md, .DS_Store is skipped, main.go backup, editor temp file like foo.tpl~ or foo.go) sits directly under <templateDir>/server; also .tpl.bak or any renamed file in the "server" level.

Common situations: Developers adding notes or compiled artifacts into the template folder; OS/editor leaving backup/temp files; copying real Go source instead of .tpl templates into server/.

Related errors


AI-assisted analysis of flipped-aurora/gin-vue-admin@3136500ef3 (2026-08-31). Data as JSON: /api/errors/9dc877c5190330f1. Report an issue: GitHub.

Appendix: source

Thrown at server/service/system/auto_code_package.go:331

		switch templateDirs[i].Name() {
		case "server":
			if !info.GenerateServer && !isPackage {
				break
			}
			var secondDirs []os.DirEntry
			secondDirs, err = os.ReadDir(second)
			if err != nil {
				return nil, nil, nil, errors.Wrapf(err, "读取模版文件夹[%s]失败!", second)
			}
			for j := 0; j < len(secondDirs); j++ {
				if secondDirs[j].Name() == ".DS_Store" {
					continue
				}
				three := filepath.Join(second, secondDirs[j].Name())
				if !secondDirs[j].IsDir() {
					ext := filepath.Ext(secondDirs[j].Name())
					if ext != ".tpl" {
						return nil, nil, nil, errors.Errorf("[filpath:%s]非法模版后缀!", three)
					}
					name := strings.TrimSuffix(secondDirs[j].Name(), ext)
					if name == "main.go" || name == "plugin.go" {
						pluginInitialize := &ast.PluginInitializeV2{
							Type:        ast.TypePluginInitializeV2,
							Path:        filepath.Join(global.GVA_CONFIG.AutoCode.Root, global.GVA_CONFIG.AutoCode.Server, "plugin", entity.PackageName, name),
							PluginPath:  filepath.Join(global.GVA_CONFIG.AutoCode.Root, global.GVA_CONFIG.AutoCode.Server, "plugin", "register.go"),
							ImportPath:  fmt.Sprintf(`"%s/plugin/%s"`, global.GVA_CONFIG.AutoCode.Module, entity.PackageName),
							PackageName: entity.PackageName,
						}
						asts[pluginInitialize.PluginPath+"=>"+pluginInitialize.Type.String()] = pluginInitialize
						creates[three] = pluginInitialize.Path
						continue
					}
					return nil, nil, nil, errors.Errorf("[filpath:%s]非法模版文件!", three)
				}
				switch secondDirs[j].Name() {
				case "api", "router", "service":

View on GitHub (pinned to 3136500ef3)