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