Add goctl version to code header (#4293)

This commit is contained in:
kesonan 2024-08-03 22:22:51 +08:00 committed by GitHub
parent dedba17219
commit 64e3aeda55
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 28 additions and 2 deletions

View File

@ -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,
},
})
}

View File

@ -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,
},
})
}

View File

@ -1,4 +1,6 @@
// Code generated by goctl. DO NOT EDIT.
// goctl {{.version}}
package types{{if .containsTime}}
import (
"time"

View File

@ -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;

View File

@ -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

View File

@ -1,3 +1,4 @@
// Code generated by goctl. DO NOT EDIT.
// goctl {{.version}}
{{.componentTypes}}

View File

@ -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,
})
}

View File

@ -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
}

View File

@ -1,4 +1,6 @@
// Code generated by goctl. DO NOT EDIT.
// goctl {{.version}}
package model
import (

View File

@ -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
//

View File

@ -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()
}