servicechecker/pkg/grpcconn/grpcconn.go

31 lines
675 B
Go
Raw Normal View History

package grpcconn
import (
"context"
"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{}) 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
}