servicechecker/pkg/grpcconn/grpcconn.go
Vasiliy Tolstov 1bba83e6fc initial http support
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2024-11-16 23:57:58 +03:00

38 lines
922 B
Go

package grpcconn
import (
"context"
"strings"
"time"
"github.com/google/uuid"
"go.unistack.org/micro/v3/client"
"go.unistack.org/micro/v3/logger"
)
func Call(ctx context.Context, l logger.Logger, c client.Client, addr string, td time.Duration, req client.Request, rsp interface{}, opts ...client.CallOption) error {
var err error
uid, err := uuid.NewRandom()
if err != nil {
l.Error(ctx, "failed to generate x-request-id", err)
return err
}
err = c.Call(ctx, req, rsp,
client.WithAddress(addr),
client.WithRequestTimeout(td),
// client.WithContentType("application/json"),
)
if err != nil {
l.Error(ctx, "call failed", "x-request-id", uid.String(), err)
return err
}
return nil
}
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:]
}