fix: add service and add rpc api
This commit is contained in:
parent
696184f41a
commit
67ae76c9b9
@ -68,3 +68,10 @@ message DownloadResp {}
|
|||||||
message UpdateUserInfoReq {}
|
message UpdateUserInfoReq {}
|
||||||
|
|
||||||
message UpdateUserInfoResp {}
|
message UpdateUserInfoResp {}
|
||||||
|
|
||||||
|
|
||||||
|
// @route_group: true
|
||||||
|
// @route_api: /
|
||||||
|
// @gen_to: ./
|
||||||
|
service UserInfo {}
|
||||||
|
|
||||||
|
|||||||
21
gobuf.go
21
gobuf.go
@ -2,6 +2,7 @@ package gobuf
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"fmt"
|
||||||
"github.com/emicklei/proto"
|
"github.com/emicklei/proto"
|
||||||
"gitter.top/sync/proto-contrib/pkg/protofmt"
|
"gitter.top/sync/proto-contrib/pkg/protofmt"
|
||||||
"io"
|
"io"
|
||||||
@ -104,6 +105,26 @@ func (parser *Parser) AddRPC(serviceName, rpcName string) error {
|
|||||||
return parser.writeSync()
|
return parser.writeSync()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (parser *Parser) AddService(serviceName string) error {
|
||||||
|
if parser.ExistService(serviceName) {
|
||||||
|
return fmt.Errorf("service name exist")
|
||||||
|
}
|
||||||
|
|
||||||
|
parser.proto.Elements = append(parser.proto.Elements, &proto.Service{
|
||||||
|
Comment: &proto.Comment{
|
||||||
|
Lines: []string{
|
||||||
|
" @route_group: true",
|
||||||
|
" @base_url: /api/" + calm2Case(serviceName),
|
||||||
|
" @gen_to: ./internal/controller/" + calm2Case(serviceName) + ".go",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Name: serviceName,
|
||||||
|
Parent: parser.proto,
|
||||||
|
})
|
||||||
|
|
||||||
|
return parser.writeSync()
|
||||||
|
}
|
||||||
|
|
||||||
func (parser *Parser) writeSync() error {
|
func (parser *Parser) writeSync() error {
|
||||||
var buf = new(bytes.Buffer)
|
var buf = new(bytes.Buffer)
|
||||||
|
|
||||||
|
|||||||
@ -20,3 +20,10 @@ func TestParser_AddRPC(t *testing.T) {
|
|||||||
err = parser.AddRPC("File", "UpdateUserInfo")
|
err = parser.AddRPC("File", "UpdateUserInfo")
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestParser_AddService(t *testing.T) {
|
||||||
|
parser, err := NewParser("example.proto")
|
||||||
|
assert.Nil(t, err)
|
||||||
|
err = parser.AddService("UserInfo")
|
||||||
|
assert.Nil(t, err)
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user