Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
5758c7dfd5 | |||
de02d636ad | |||
6f4e54a876 | |||
|
47c8975a12 | ||
1228768700 |
2
.github/workflows/build.yml
vendored
2
.github/workflows/build.yml
vendored
@@ -12,7 +12,7 @@ jobs:
|
||||
- name: setup
|
||||
uses: actions/setup-go@v2
|
||||
with:
|
||||
go-version: 1.16
|
||||
go-version: 1.17
|
||||
- name: checkout
|
||||
uses: actions/checkout@v3
|
||||
- name: cache
|
||||
|
2
.github/workflows/codeql-analysis.yml
vendored
2
.github/workflows/codeql-analysis.yml
vendored
@@ -47,7 +47,7 @@ jobs:
|
||||
- name: setup
|
||||
uses: actions/setup-go@v2
|
||||
with:
|
||||
go-version: 1.16
|
||||
go-version: 1.17
|
||||
# Initializes the CodeQL tools for scanning.
|
||||
- name: init
|
||||
uses: github/codeql-action/init@v1
|
||||
|
2
.github/workflows/pr.yml
vendored
2
.github/workflows/pr.yml
vendored
@@ -12,7 +12,7 @@ jobs:
|
||||
- name: setup
|
||||
uses: actions/setup-go@v2
|
||||
with:
|
||||
go-version: 1.16
|
||||
go-version: 1.17
|
||||
- name: checkout
|
||||
uses: actions/checkout@v3
|
||||
- name: cache
|
||||
|
4
drpc.go
4
drpc.go
@@ -30,6 +30,9 @@ type drpcClient struct {
|
||||
|
||||
func (d *drpcClient) call(ctx context.Context, addr string, req client.Request, rsp interface{}, opts client.CallOptions) error {
|
||||
var header map[string]string
|
||||
if strings.HasPrefix(addr, "http") {
|
||||
addr = addr[strings.Index(addr, ":")+3:]
|
||||
}
|
||||
|
||||
if md, ok := metadata.FromOutgoingContext(ctx); ok {
|
||||
header = make(map[string]string, len(md))
|
||||
@@ -90,6 +93,7 @@ func (d *drpcClient) call(ctx context.Context, addr string, req client.Request,
|
||||
*/
|
||||
ch := make(chan error, 1)
|
||||
_ = dialCtx
|
||||
|
||||
// rc, err := net.DialContext(ctx, "tcp", addr)
|
||||
rc, err := net.Dial("tcp", addr)
|
||||
if err != nil {
|
||||
|
2
go.mod
2
go.mod
@@ -4,5 +4,5 @@ go 1.16
|
||||
|
||||
require (
|
||||
go.unistack.org/micro/v3 v3.8.21
|
||||
storj.io/drpc v0.0.29
|
||||
storj.io/drpc v0.0.30
|
||||
)
|
||||
|
4
go.sum
4
go.sum
@@ -153,5 +153,5 @@ gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C
|
||||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
storj.io/drpc v0.0.29 h1:Ihd4ls/JQFr0lctefie3iu+3QM4duccCKr9uMzf4sKY=
|
||||
storj.io/drpc v0.0.29/go.mod h1:6rcOyR/QQkSTX/9L5ZGtlZaE2PtXTTZl8d+ulSeeYEg=
|
||||
storj.io/drpc v0.0.30 h1:jqPe4T9KEu3CDBI05A2hCMgMSHLtd/E0N0yTF9QreIE=
|
||||
storj.io/drpc v0.0.30/go.mod h1:6rcOyR/QQkSTX/9L5ZGtlZaE2PtXTTZl8d+ulSeeYEg=
|
||||
|
21
request.go
21
request.go
@@ -18,24 +18,19 @@ type drpcRequest struct {
|
||||
}
|
||||
|
||||
// service Struct.Method /service.Struct/Method
|
||||
func methodToDRPC(service, method string) string {
|
||||
// no method or already grpc method
|
||||
func methodToDRPC(service string, method string) string {
|
||||
// no method or already drpc method
|
||||
if len(method) == 0 || method[0] == '/' {
|
||||
return method
|
||||
}
|
||||
|
||||
// assume method is Foo.Bar
|
||||
mParts := strings.Split(method, ".")
|
||||
if len(mParts) != 2 {
|
||||
return method
|
||||
idx := strings.LastIndex(method, ".")
|
||||
if len(method) < 3 || idx < 2 {
|
||||
return fmt.Sprintf("/%s.%s", strings.Title(service), method)
|
||||
}
|
||||
|
||||
if len(service) == 0 {
|
||||
return fmt.Sprintf("/%s/%s", mParts[0], mParts[1])
|
||||
}
|
||||
|
||||
// return /pkg.Foo/Bar
|
||||
return fmt.Sprintf("/%s.%s/%s", strings.Title(service), mParts[0], mParts[1])
|
||||
drpcService := method[:idx]
|
||||
drpcMethod := method[idx+1:]
|
||||
return fmt.Sprintf("/%s/%s", drpcService, drpcMethod)
|
||||
}
|
||||
|
||||
func newDRPCRequest(service, method string, request interface{}, contentType string, reqOpts ...client.RequestOption) client.Request {
|
||||
|
@@ -12,7 +12,7 @@ func TestMethodToDRPC(t *testing.T) {
|
||||
}{
|
||||
{
|
||||
"helloworld",
|
||||
"Greeter.SayHello",
|
||||
"Greeter/SayHello",
|
||||
"/Helloworld.Greeter/SayHello",
|
||||
},
|
||||
{
|
||||
|
Reference in New Issue
Block a user