diff --git a/tools/goctl/api/gogen/genroutes.go b/tools/goctl/api/gogen/genroutes.go index 528cad4a..6d9295f7 100644 --- a/tools/goctl/api/gogen/genroutes.go +++ b/tools/goctl/api/gogen/genroutes.go @@ -13,6 +13,7 @@ import ( "github.com/zeromicro/go-zero/core/collection" "github.com/zeromicro/go-zero/tools/goctl/api/spec" "github.com/zeromicro/go-zero/tools/goctl/config" + "github.com/zeromicro/go-zero/tools/goctl/internal/version" "github.com/zeromicro/go-zero/tools/goctl/util/format" "github.com/zeromicro/go-zero/tools/goctl/util/pathx" "github.com/zeromicro/go-zero/tools/goctl/vars" @@ -22,6 +23,8 @@ const ( jwtTransKey = "jwtTransition" routesFilename = "routes" routesTemplate = `// Code generated by goctl. DO NOT EDIT. +// goctl {{.version}} + package handler import ( @@ -203,6 +206,7 @@ rest.WithPrefix("%s"),`, g.prefix) "hasTimeout": hasTimeout, "importPackages": genRouteImports(rootPkg, api), "routesAdditions": strings.TrimSpace(builder.String()), + "version": version.BuildVersion, }, }) } diff --git a/tools/goctl/api/gogen/gentypes.go b/tools/goctl/api/gogen/gentypes.go index 6ddcbbfd..5ee51abe 100644 --- a/tools/goctl/api/gogen/gentypes.go +++ b/tools/goctl/api/gogen/gentypes.go @@ -11,6 +11,7 @@ import ( "github.com/zeromicro/go-zero/tools/goctl/api/spec" apiutil "github.com/zeromicro/go-zero/tools/goctl/api/util" "github.com/zeromicro/go-zero/tools/goctl/config" + "github.com/zeromicro/go-zero/tools/goctl/internal/version" "github.com/zeromicro/go-zero/tools/goctl/util" "github.com/zeromicro/go-zero/tools/goctl/util/format" ) @@ -64,6 +65,7 @@ func genTypes(dir string, cfg *config.Config, api *spec.ApiSpec) error { data: map[string]any{ "types": val, "containsTime": false, + "version": version.BuildVersion, }, }) } diff --git a/tools/goctl/api/gogen/types.tpl b/tools/goctl/api/gogen/types.tpl index 735ec2da..8015c579 100644 --- a/tools/goctl/api/gogen/types.tpl +++ b/tools/goctl/api/gogen/types.tpl @@ -1,4 +1,6 @@ // Code generated by goctl. DO NOT EDIT. +// goctl {{.version}} + package types{{if .containsTime}} import ( "time" diff --git a/tools/goctl/api/javagen/component.tpl b/tools/goctl/api/javagen/component.tpl index 0bb309f3..62e7bfe1 100644 --- a/tools/goctl/api/javagen/component.tpl +++ b/tools/goctl/api/javagen/component.tpl @@ -1,4 +1,6 @@ // Code generated by goctl. DO NOT EDIT. +// goctl {{.version}} + package com.xhb.logic.http.packet.{{.packet}}.model; import org.jetbrains.annotations.NotNull; diff --git a/tools/goctl/api/javagen/gencomponents.go b/tools/goctl/api/javagen/gencomponents.go index c8463d41..0f78df27 100644 --- a/tools/goctl/api/javagen/gencomponents.go +++ b/tools/goctl/api/javagen/gencomponents.go @@ -14,6 +14,7 @@ import ( "github.com/zeromicro/go-zero/core/stringx" "github.com/zeromicro/go-zero/tools/goctl/api/spec" apiutil "github.com/zeromicro/go-zero/tools/goctl/api/util" + "github.com/zeromicro/go-zero/tools/goctl/internal/version" "github.com/zeromicro/go-zero/tools/goctl/util" "github.com/zeromicro/go-zero/tools/goctl/util/pathx" ) @@ -131,6 +132,7 @@ func (c *componentsContext) createComponent(dir, packetName string, ty spec.Type "className": util.Title(defineStruct.Name()), "superClassName": superClassName, "HasProperty": len(strings.TrimSpace(propertiesString)) > 0, + "version": version.BuildVersion, }) if err != nil { return err diff --git a/tools/goctl/api/tsgen/components.tpl b/tools/goctl/api/tsgen/components.tpl index aabe0194..7f138c8e 100644 --- a/tools/goctl/api/tsgen/components.tpl +++ b/tools/goctl/api/tsgen/components.tpl @@ -1,3 +1,4 @@ // Code generated by goctl. DO NOT EDIT. +// goctl {{.version}} {{.componentTypes}} diff --git a/tools/goctl/api/tsgen/gencomponents.go b/tools/goctl/api/tsgen/gencomponents.go index fab8ebd0..64855163 100644 --- a/tools/goctl/api/tsgen/gencomponents.go +++ b/tools/goctl/api/tsgen/gencomponents.go @@ -8,6 +8,7 @@ import ( "github.com/zeromicro/go-zero/tools/goctl/api/spec" apiutil "github.com/zeromicro/go-zero/tools/goctl/api/util" + "github.com/zeromicro/go-zero/tools/goctl/internal/version" "github.com/zeromicro/go-zero/tools/goctl/util/pathx" ) @@ -61,5 +62,6 @@ func genComponents(dir string, api *spec.ApiSpec) error { t := template.Must(template.New("componentsTemplate").Parse(componentsTemplate)) return t.Execute(fp, map[string]string{ "componentTypes": val, + "version": version.BuildVersion, }) } diff --git a/tools/goctl/model/mongo/generate/generate.go b/tools/goctl/model/mongo/generate/generate.go index 3d3baa86..9b9f09c4 100644 --- a/tools/goctl/model/mongo/generate/generate.go +++ b/tools/goctl/model/mongo/generate/generate.go @@ -5,6 +5,7 @@ import ( "path/filepath" "github.com/zeromicro/go-zero/tools/goctl/config" + "github.com/zeromicro/go-zero/tools/goctl/internal/version" "github.com/zeromicro/go-zero/tools/goctl/model/mongo/template" "github.com/zeromicro/go-zero/tools/goctl/util" "github.com/zeromicro/go-zero/tools/goctl/util/format" @@ -59,6 +60,7 @@ func generateModel(ctx *Context) error { "Type": stringx.From(t).Title(), "lowerType": stringx.From(t).Untitle(), "Cache": ctx.Cache, + "version": version.BuildVersion, }, output, true); err != nil { return err } diff --git a/tools/goctl/model/mongo/template/model.tpl b/tools/goctl/model/mongo/template/model.tpl index 287125d9..6f8fa83d 100644 --- a/tools/goctl/model/mongo/template/model.tpl +++ b/tools/goctl/model/mongo/template/model.tpl @@ -1,4 +1,6 @@ // Code generated by goctl. DO NOT EDIT. +// goctl {{.version}} + package model import ( diff --git a/tools/goctl/model/sql/template/template.go b/tools/goctl/model/sql/template/template.go index 99cb3b19..78fed2aa 100644 --- a/tools/goctl/model/sql/template/template.go +++ b/tools/goctl/model/sql/template/template.go @@ -4,6 +4,7 @@ import ( _ "embed" "fmt" + "github.com/zeromicro/go-zero/tools/goctl/internal/version" "github.com/zeromicro/go-zero/tools/goctl/util" ) @@ -44,6 +45,8 @@ var ModelCustom string // ModelGen defines a template for model var ModelGen = fmt.Sprintf(`%s +// versions: +// goctl version: %s package {{.pkg}} {{.imports}} @@ -57,7 +60,7 @@ package {{.pkg}} {{.extraMethod}} {{.tableName}} {{.customized}} -`, util.DoNotEditHead) +`, util.DoNotEditHead, version.BuildVersion) // Insert defines a template for insert code in model // diff --git a/tools/goctl/util/head.go b/tools/goctl/util/head.go index 6e76b12e..03425d46 100644 --- a/tools/goctl/util/head.go +++ b/tools/goctl/util/head.go @@ -1,17 +1,21 @@ package util +import "github.com/zeromicro/go-zero/tools/goctl/internal/version" + const ( // DoNotEditHead added to the beginning of a file to prompt the user not to edit DoNotEditHead = "// Code generated by goctl. DO NOT EDIT." headTemplate = DoNotEditHead + ` +// goctl {{.version}} // Source: {{.source}}` ) // GetHead returns a code head string with source filename func GetHead(source string) string { buffer, _ := With("head").Parse(headTemplate).Execute(map[string]any{ - "source": source, + "source": source, + "version": version.BuildVersion, }) return buffer.String() }