feat: add rpc
This commit is contained in:
parent
1775a7b444
commit
dda09f2e32
@ -10,7 +10,7 @@ package main
|
||||
import "gitter.top/common/gobuf"
|
||||
|
||||
func main() {
|
||||
parser, err := NewParser("example.proto")
|
||||
parser, err := gobuf.NewParser("example.proto")
|
||||
if err != nil {
|
||||
// do something
|
||||
}
|
||||
|
18
gobuf.go
18
gobuf.go
@ -81,25 +81,25 @@ func (parser *Parser) AddRPC(serviceName, rpcName string) error {
|
||||
service.Elements = append(service.Elements, &proto.RPC{
|
||||
Comment: &proto.Comment{
|
||||
Lines: []string{
|
||||
" @desc: ",
|
||||
" @author: ",
|
||||
" @method: ",
|
||||
" @desc: 描述",
|
||||
" @author: 作者",
|
||||
" @method: GET",
|
||||
" @api: /" + calm2Case(rpcName),
|
||||
},
|
||||
},
|
||||
Name: rpcName,
|
||||
RequestType: rpcName + "Req",
|
||||
ReturnsType: rpcName + "Resp",
|
||||
RequestType: toUpperCamlCase(serviceName) + toUpperCamlCase(rpcName) + "Req",
|
||||
ReturnsType: toUpperCamlCase(serviceName) + toUpperCamlCase(rpcName) + "Resp",
|
||||
Parent: service,
|
||||
})
|
||||
}))
|
||||
|
||||
parser.proto.Elements = append(parser.proto.Elements, &proto.Message{
|
||||
Name: rpcName + "Req",
|
||||
Name: toUpperCamlCase(serviceName) + toUpperCamlCase(rpcName) + "Req",
|
||||
Parent: parser.proto,
|
||||
})
|
||||
parser.proto.Elements = append(parser.proto.Elements, &proto.Message{
|
||||
Name: rpcName + "Resp",
|
||||
Name: toUpperCamlCase(serviceName) + toUpperCamlCase(rpcName) + "Resp",
|
||||
Parent: parser.proto,
|
||||
})
|
||||
|
||||
@ -115,8 +115,8 @@ func (parser *Parser) AddService(serviceName string) error {
|
||||
Comment: &proto.Comment{
|
||||
Lines: []string{
|
||||
" @route_group: true",
|
||||
" @base_url: /api/" + calm2Case(serviceName),
|
||||
" @gen_to: ./internal/controller/" + calm2Case(serviceName) + "_controller.go",
|
||||
" @base_url: /v1/" + calm2Case(serviceName),
|
||||
" @gen_to: ./api_services/v1/" + calm2Case(serviceName) + "_controller.go",
|
||||
},
|
||||
},
|
||||
Name: serviceName,
|
||||
|
@ -26,4 +26,6 @@ func TestParser_AddService(t *testing.T) {
|
||||
assert.Nil(t, err)
|
||||
err = parser.AddService("UserInfo")
|
||||
assert.Nil(t, err)
|
||||
err = parser.AddRPC("UserInfo", "Detail")
|
||||
assert.Nil(t, err)
|
||||
}
|
||||
|
7
utils.go
7
utils.go
@ -28,6 +28,13 @@ func toLowerCamelCase(str string) string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func toUpperCamlCase(str string) string {
|
||||
if len(str) != 0 {
|
||||
return string(unicode.ToUpper(rune(str[0]))) + str[1:]
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func getFieldValue(fieldName string, cases TagValueStyle) string {
|
||||
switch cases {
|
||||
case Underline:
|
||||
|
Loading…
Reference in New Issue
Block a user