2024-08-08 12:00:49: merge [master:958e40c1b5f280b681f8c9bf09c476b347ea7b7e];
This commit is contained in:
1 parent
bdbb3216ce
commit
d8a0db34ef
25 files changed
+1752
-1
No files matched your search
@@ -0,0 +1,38 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/txix-open/isp-kit/grpc/client"
|
||||
md "google.golang.org/grpc/metadata"
|
||||
)
|
||||
|
||||
type Router struct {
|
||||
cli *client.Client
|
||||
}
|
||||
|
||||
func NewRouter(cli *client.Client) Router {
|
||||
return Router{
|
||||
cli: cli,
|
||||
}
|
||||
}
|
||||
|
||||
func (i Router) Invoke(methodPath string, request interface{}, metadata map[string]interface{}) (interface{}, error) {
|
||||
ctx := context.Background()
|
||||
newMd := md.New(nil)
|
||||
for key, val := range metadata {
|
||||
newMd.Set(key, fmt.Sprint(val))
|
||||
}
|
||||
ctx = md.NewOutgoingContext(ctx, newMd)
|
||||
|
||||
var response interface{}
|
||||
|
||||
err := i.cli.Invoke(methodPath).JsonRequestBody(request).JsonResponseBody(&response).Do(ctx)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "invoke")
|
||||
}
|
||||
|
||||
return response, nil
|
||||
}
|
||||
Reference in new issue
Block a user