feat: generate plugin version

This commit is contained in:
xuthus5 2024-04-20 01:37:15 +08:00
parent d1f399b03d
commit 35eb0a9164
Signed by: xuthus5
GPG Key ID: A23CF9620CBB55F9
1 changed files with 19 additions and 7 deletions

26
main.go
View File

@ -4,16 +4,28 @@ import (
"bytes"
"flag"
"fmt"
"os"
"path/filepath"
"strings"
"time"
"github.com/emicklei/proto"
"gitter.top/common/protofmt"
"google.golang.org/protobuf/compiler/protogen"
"os"
"path/filepath"
"runtime/debug"
"strings"
)
var (
version string
)
func init() {
info, ok := debug.ReadBuildInfo()
if !ok {
version = "unknown"
return
}
version = info.Main.Version
}
type Coco struct {
DisableGenerateRouter bool // 禁止路由信息生成
DisableGenerateMongoModel bool // 禁止mongo信息生成
@ -109,7 +121,7 @@ func (c *Coco) generateRouterMap(plugin *protogen.Plugin) {
g := plugin.NewGeneratedFile(filename, pbFile.GoImportPath)
g.P("// Code generated by protoc-gen-coco. DO NOT EDIT.")
g.P("// source: ", pbFile.GeneratedFilenamePrefix, ".proto")
g.P("// generate at: ", time.Now().Format("2006-01-02 15:04:05"))
g.P("// protoc-gen-coco: ", version)
g.P()
g.P("package ", pbFile.GoPackageName)
g.P()
@ -224,7 +236,7 @@ func (c *Coco) generateMongoModel(plugin *protogen.Plugin) {
g := plugin.NewGeneratedFile(filename, pbFile.GoImportPath)
g.P("// Code generated by protoc-gen-coco. DO NOT EDIT.")
g.P("// source: ", pbFile.GeneratedFilenamePrefix, ".proto")
g.P("// generate at: ", time.Now().Format("2006-01-02 15:04:05"))
g.P("// protoc-gen-coco: ", version)
g.P()
g.P("package ", pbFile.GoPackageName)
g.P()