2024-11-16 15:21:52 +03:00
|
|
|
package grpcconn
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2024-11-16 19:57:00 +03:00
|
|
|
"strings"
|
2024-11-16 15:21:52 +03:00
|
|
|
"time"
|
|
|
|
|
|
|
|
"go.unistack.org/micro/v3/client"
|
|
|
|
"go.unistack.org/micro/v3/logger"
|
|
|
|
)
|
|
|
|
|
2024-11-17 18:54:44 +03:00
|
|
|
func Call(ctx context.Context, rquid string, l logger.Logger, c client.Client, addr string, td time.Duration, req client.Request, rsp interface{}, opts ...client.CallOption) error {
|
2024-11-16 15:21:52 +03:00
|
|
|
var err error
|
|
|
|
|
|
|
|
err = c.Call(ctx, req, rsp,
|
|
|
|
client.WithAddress(addr),
|
|
|
|
client.WithRequestTimeout(td),
|
|
|
|
// client.WithContentType("application/json"),
|
|
|
|
)
|
|
|
|
if err != nil {
|
2024-11-17 18:54:44 +03:00
|
|
|
l.Error(ctx, "call failed", "x-request-id", rquid, err)
|
2024-11-16 15:21:52 +03:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
2024-11-16 19:57:00 +03:00
|
|
|
|
|
|
|
func ServiceMethod(method string) (string, string, string) {
|
|
|
|
idx1 := strings.LastIndex(method, ".")
|
|
|
|
idx2 := strings.Index(method[:idx1], ".")
|
|
|
|
return method[:idx2], method[idx2+1 : idx1], method[idx1+1:]
|
|
|
|
}
|