feat: support add api and router group command
This commit is contained in:
parent
d5854a4c62
commit
a7316847a9
|
@ -25,6 +25,8 @@ func init() {
|
|||
})
|
||||
rootCmd.AddCommand(bootstrap.Update())
|
||||
rootCmd.AddCommand(bootstrap.CreateProject())
|
||||
rootCmd.AddCommand(bootstrap.AddAPICommand())
|
||||
rootCmd.AddCommand(bootstrap.AddServiceCommand())
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
|
|
@ -0,0 +1,76 @@
|
|||
package bootstrap
|
||||
|
||||
import (
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/spf13/cobra"
|
||||
"gitter.top/coco/gobuf"
|
||||
"os"
|
||||
)
|
||||
|
||||
func AddAPICommand() *cobra.Command {
|
||||
pbPath, _ := os.Getwd()
|
||||
var routerGroup = ""
|
||||
var routerName = ""
|
||||
cmd := &cobra.Command{
|
||||
Use: "addapi",
|
||||
Short: "add api for service",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if routerName == "" {
|
||||
logrus.Errorf("router name --name empty")
|
||||
return
|
||||
}
|
||||
routerName = FirstUpper(routerName)
|
||||
buf, err := gobuf.NewParser(pbPath)
|
||||
if err != nil {
|
||||
logrus.Errorf("read proto file failed: %v", err)
|
||||
return
|
||||
}
|
||||
if buf.ExistRPC(routerGroup, routerName) {
|
||||
logrus.Warnf("router name exist")
|
||||
return
|
||||
}
|
||||
err = buf.AddRPC(routerGroup, routerName)
|
||||
if err != nil {
|
||||
logrus.Warnf("add router failed: %v", err)
|
||||
return
|
||||
}
|
||||
},
|
||||
}
|
||||
cmd.Flags().StringVar(&pbPath, "path", pbPath, "proto file path")
|
||||
cmd.Flags().StringVar(&routerName, "name", routerName, "api name")
|
||||
cmd.Flags().StringVar(&routerGroup, "service", routerGroup, "service name")
|
||||
return cmd
|
||||
}
|
||||
|
||||
func AddServiceCommand() *cobra.Command {
|
||||
var pbPath = ""
|
||||
var svcName = ""
|
||||
cmd := &cobra.Command{
|
||||
Use: "addgroup",
|
||||
Short: "add router group",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if svcName == "" {
|
||||
logrus.Errorf("router group name -- name empty")
|
||||
return
|
||||
}
|
||||
|
||||
buf, err := gobuf.NewParser(pbPath)
|
||||
if err != nil {
|
||||
logrus.Errorf("read proto file failed: %v", err)
|
||||
return
|
||||
}
|
||||
if buf.ExistService(svcName) {
|
||||
logrus.Errorf("router group name exist")
|
||||
return
|
||||
}
|
||||
if err := buf.AddService(svcName); err != nil {
|
||||
logrus.Errorf("add router group failed: %+v", err)
|
||||
return
|
||||
}
|
||||
},
|
||||
}
|
||||
cmd.Flags().StringVar(&pbPath, "path", pbPath, "proto file path")
|
||||
cmd.Flags().StringVar(&svcName, "name", svcName, "router group name, such as UserModule")
|
||||
|
||||
return cmd
|
||||
}
|
3
go.mod
3
go.mod
|
@ -10,9 +10,12 @@ require (
|
|||
|
||||
require (
|
||||
code.gitea.io/sdk/gitea v0.15.1 // indirect
|
||||
github.com/emicklei/proto v1.11.1 // indirect
|
||||
github.com/hashicorp/go-version v1.2.1 // indirect
|
||||
github.com/inconshreveable/mousetrap v1.0.1 // indirect
|
||||
github.com/spf13/pflag v1.0.5 // indirect
|
||||
gitter.top/coco/gobuf v0.0.0-20230320172921-67ae76c9b96b // indirect
|
||||
gitter.top/sync/proto-contrib v0.15.0 // indirect
|
||||
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue