-
Notifications
You must be signed in to change notification settings - Fork 0
/
gomod.go
47 lines (42 loc) · 1.15 KB
/
gomod.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package proj
import (
"github.com/brunowang/gframe/cmd/protoc-gen-go-gframe/gen/helper"
"google.golang.org/protobuf/compiler/protogen"
)
type GoMod struct {
plugin *protogen.Plugin
}
func (a *GoMod) Setup(plugin *protogen.Plugin) {
a.plugin = plugin
}
func (a *GoMod) Generate(config helper.GenerateConfig) {
for _, file := range a.plugin.Files {
if !file.Generate {
continue
}
fdir := helper.GetFileBaseDir(file, config)
fpath := fdir + "/go.mod"
pbGoDir := string(file.GoImportPath)
if config.PbGoDir != "" {
pbGoDir = config.PbGoDir
}
g := a.plugin.NewGeneratedFile(fpath, file.GoImportPath)
g.P("module " + fdir)
g.P()
g.P("go 1.18")
g.P()
g.P("require (")
g.P("\t" + pbGoDir + " latest")
g.P("\tgithub.com/brunowang/gframe latest")
g.P("\tgithub.com/gin-gonic/gin v1.9.1")
g.P("\tgithub.com/golang/protobuf v1.5.2")
g.P("\tgithub.com/gorilla/websocket v1.4.2")
g.P("\tgithub.com/grpc-ecosystem/go-grpc-middleware v1.3.0")
g.P("\tgithub.com/soheilhy/cmux v0.1.5")
g.P("\tgo.uber.org/zap v1.22.0")
g.P("\tgoogle.golang.org/grpc v1.49.0")
g.P("\tgopkg.in/alecthomas/kingpin.v2 v2.2.6")
g.P(")")
break
}
}