diff --git a/console/commands/bean.go b/console/commands/bean.go index 1b58211..c8d767a 100644 --- a/console/commands/bean.go +++ b/console/commands/bean.go @@ -229,8 +229,11 @@ func getInitializeNewFunName(k parser.GoTypeAttr, m map[string]string) string { } beanValueNextVal := strings.Trim(beanValue[startTemp+1:], ")") got = got + ".GetBean(*" + providers + "GetBean(\"" + beanValueNextName + "\").(" + providers + "Bean).GetBean(\"" + beanValueNextVal + "\").(*string))" - } else { + } else if tag.Count() == 2 { got = got + ".GetBean(\"" + beanValue + "\")" + } else if tag.Count() == 3 { + beanValue = beanValue + ", " + tag.Get(2) + got = got + ".GetBean(`" + beanValue + "`)" } return got + ".(*" + alias + name + ")" diff --git a/console/commands/grpc.go b/console/commands/grpc.go new file mode 100644 index 0000000..2f8bebe --- /dev/null +++ b/console/commands/grpc.go @@ -0,0 +1,46 @@ +package commands + +import ( + "fmt" + "github.com/ctfang/command" + "github.com/go-home-admin/toolset/parser" + "strings" +) + +// GrpcCommand @Bean +type GrpcCommand struct{} + +func (GrpcCommand) Configure() command.Configure { + return command.Configure{ + Name: "make:grpc", + Description: "根据protoc文件定义, 生成路grpc基础文件", + Input: command.Argument{ + Option: []command.ArgParam{ + { + Name: "path", + Description: "只解析指定目录", + Default: "@root/protobuf/endpoint", + }, + }, + }, + } +} + +// TODO +func (GrpcCommand) Execute(input command.Input) { + root := getRootPath() + module := getModModule() + + _ = module + + path := input.GetOption("path") + path = strings.Replace(path, "@root", root, 1) + + for _, parsers := range parser.NewProtocParserForDir(path) { + for _, fileParser := range parsers { + for _, service := range fileParser.Services { + fmt.Println(service) + } + } + } +} diff --git a/console/commands/z_inject_gen.go b/console/commands/z_inject_gen.go index d1ea2ea..2708750 100644 --- a/console/commands/z_inject_gen.go +++ b/console/commands/z_inject_gen.go @@ -8,6 +8,7 @@ import ( var _BeanCommandSingle *BeanCommand var _CurdCommandSingle *CurdCommand var _DevCommandSingle *DevCommand +var _GrpcCommandSingle *GrpcCommand var _JsSingle *Js var _MongoCommandSingle *MongoCommand var _OrmCommandSingle *OrmCommand @@ -20,6 +21,7 @@ func GetAllProvider() []interface{} { NewBeanCommand(), NewCurdCommand(), NewDevCommand(), + NewGrpcCommand(), NewJs(), NewMongoCommand(), NewOrmCommand(), @@ -50,6 +52,13 @@ func NewDevCommand() *DevCommand { } return _DevCommandSingle } +func NewGrpcCommand() *GrpcCommand { + if _GrpcCommandSingle == nil { + _GrpcCommandSingle = &GrpcCommand{} + providers.AfterProvider(_GrpcCommandSingle, "") + } + return _GrpcCommandSingle +} func NewJs() *Js { if _JsSingle == nil { _JsSingle = &Js{}