Skip to content

Commit

Permalink
add: bean 允许默认值
Browse files Browse the repository at this point in the history
  • Loading branch information
cyz-home committed Feb 9, 2023
1 parent 0e1bf8b commit 13e0f06
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 1 deletion.
5 changes: 4 additions & 1 deletion console/commands/bean.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 + ")"
Expand Down
46 changes: 46 additions & 0 deletions console/commands/grpc.go
Original file line number Diff line number Diff line change
@@ -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)
}
}
}
}
9 changes: 9 additions & 0 deletions console/commands/z_inject_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -20,6 +21,7 @@ func GetAllProvider() []interface{} {
NewBeanCommand(),
NewCurdCommand(),
NewDevCommand(),
NewGrpcCommand(),
NewJs(),
NewMongoCommand(),
NewOrmCommand(),
Expand Down Expand Up @@ -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{}
Expand Down

0 comments on commit 13e0f06

Please sign in to comment.