diff --git a/README.md b/README.md index de26def..21cebbb 100644 --- a/README.md +++ b/README.md @@ -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 } diff --git a/gobuf.go b/gobuf.go index 94dabec..dc3d4b2 100644 --- a/gobuf.go +++ b/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, diff --git a/gobuf_test.go b/gobuf_test.go index a7d21f5..335935a 100644 --- a/gobuf_test.go +++ b/gobuf_test.go @@ -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) } diff --git a/utils.go b/utils.go index 223c9bb..f59b5f6 100644 --- a/utils.go +++ b/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: