flipped-aurora/gin-vue-admin · error

package结构异常,缺少api/v1/%s/enter.go

Error message

package结构异常,缺少api/v1/%s/enter.go

What it means

checkPackage validates that a package-type auto-code target already has the manual package skeleton in place before generating code. It stats api/v1/<Pkg>/enter.go under the configured server root; if absent, the Create call is rejected with this error. The skeleton files are the aggregation points new generated code hooks into.

Source

Thrown at server/service/system/auto_code_template.go:40

	"github.com/pkg/errors"
)

var AutoCodeTemplate = new(autoCodeTemplate)
var autoCodeCreateMu sync.Mutex

type autoCodeTemplate struct{}

func autoCodeCreateContext(ctx context.Context) context.Context {
	return context.WithoutCancel(ctx)
}

func (s *autoCodeTemplate) checkPackage(Pkg string, template string) (err error) {
	switch template {
	case "package":
		apiEnter := filepath.Join(global.GVA_CONFIG.AutoCode.Root, global.GVA_CONFIG.AutoCode.Server, "api", "v1", Pkg, "enter.go")
		_, err = os.Stat(apiEnter)
		if err != nil {
			return fmt.Errorf("package结构异常,缺少api/v1/%s/enter.go", Pkg)
		}
		serviceEnter := filepath.Join(global.GVA_CONFIG.AutoCode.Root, global.GVA_CONFIG.AutoCode.Server, "service", Pkg, "enter.go")
		_, err = os.Stat(serviceEnter)
		if err != nil {
			return fmt.Errorf("package结构异常,缺少service/%s/enter.go", Pkg)
		}
		routerEnter := filepath.Join(global.GVA_CONFIG.AutoCode.Root, global.GVA_CONFIG.AutoCode.Server, "router", Pkg, "enter.go")
		_, err = os.Stat(routerEnter)
		if err != nil {
			return fmt.Errorf("package结构异常,缺少router/%s/enter.go", Pkg)
		}
	case "plugin":
		pluginEnter := filepath.Join(global.GVA_CONFIG.AutoCode.Root, global.GVA_CONFIG.AutoCode.Server, "plugin", Pkg, "plugin.go")
		_, err = os.Stat(pluginEnter)
		if err != nil {
			return fmt.Errorf("plugin结构异常,缺少plugin/%s/plugin.go", Pkg)
		}
	}

View on GitHub (pinned to 3136500ef3)

Solutions

  1. Create the missing skeleton: server/api/v1/<Pkg>/enter.go (var <Pkg>Router = new(...), aggregated in api/v1/enter.go).
  2. Check for typos between the Pkg field in the generator UI and the actual directory name.
  3. Verify autoCode.root and autoCode.server in config.yaml point at this repo's server directory.
  4. Regenerate the package scaffold via the plugin/package init flow before running Create again.

Example fix

// before
mkdir server/api/v1/foo  // empty, no enter.go
// after
// server/api/v1/foo/enter.go
type Router struct{}
var Foo = new(Router)
Defensive patterns

Strategy: validation

Validate before calling

apiEnter := filepath.Join(cfg.AutoCode.Root, cfg.AutoCode.Server, "api", "v1", pkg, "enter.go")
if _, err := os.Stat(apiEnter); err != nil {
    return fmt.Errorf("create server/api/v1/%s/enter.go before generating", pkg)
}

Try / catch

if err := s.Create(info); err != nil {
    if strings.Contains(err.Error(), "缺少api/v1") {
        // scaffold the package then retry
    }
    return err
}

Prevention

When it happens

Trigger: Calling autoCodeTemplate.Create with template="package" and a Pkg whose api/v1/<Pkg>/enter.go does not exist under AutoCode.Root + AutoCode.Server — typically a brand-new package name that was never initialized.

Common situations: Typo in the package name in the code generator form; user deleted or renamed the enter.go; AutoCode.Root/Server config points at the wrong tree so the stat misses an existing file; repo checked out without the package scaffold.

Related errors


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