本文整理汇总了Golang中google/golang.org/grpc.Errorf函数的典型用法代码示例。如果您正苦于以下问题:Golang Errorf函数的具体用法?Golang Errorf怎么用?Golang Errorf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Errorf函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestAdminClientGetChildren
func TestAdminClientGetChildren(t *testing.T) {
connectAdminApiClient()
tests := []struct {
gcr *apipb.GetChildrenFromProfileRequest
err error
}{
{
gcr: &apipb.GetChildrenFromProfileRequest{
ProfileId: clientsub,
},
err: grpc.Errorf(2, "Invalid ID"),
},
{
gcr: &apipb.GetChildrenFromProfileRequest{},
err: grpc.Errorf(2, "Invalid ID"),
},
}
for i, tt := range tests {
_, err := apiClient.GetChildren(context.Background(), tt.gcr)
if err != tt.err {
t.Fatalf("case %d, expected %v, got %v", i, tt.err, err)
}
}
}
示例2: NewRaftProxyHealthServer
func NewRaftProxyHealthServer(local HealthServer, connSelector raftpicker.Interface, cluster raftpicker.RaftCluster, ctxMod func(context.Context) (context.Context, error)) HealthServer {
redirectChecker := func(ctx context.Context) (context.Context, error) {
s, ok := transport.StreamFromContext(ctx)
if !ok {
return ctx, grpc.Errorf(codes.InvalidArgument, "remote addr is not found in context")
}
addr := s.ServerTransport().RemoteAddr().String()
md, ok := metadata.FromContext(ctx)
if ok && len(md["redirect"]) != 0 {
return ctx, grpc.Errorf(codes.ResourceExhausted, "more than one redirect to leader from: %s", md["redirect"])
}
if !ok {
md = metadata.New(map[string]string{})
}
md["redirect"] = append(md["redirect"], addr)
return metadata.NewContext(ctx, md), nil
}
mods := []func(context.Context) (context.Context, error){redirectChecker}
mods = append(mods, ctxMod)
return &raftProxyHealthServer{
local: local,
cluster: cluster,
connSelector: connSelector,
ctxMods: mods,
}
}
示例3: request_FlowCombination_RpcPathNestedStream_2
func request_FlowCombination_RpcPathNestedStream_2(ctx context.Context, client FlowCombinationClient, req *http.Request, pathParams map[string]string) (FlowCombination_RpcPathNestedStreamClient, error) {
var protoReq NestedProto
if err := json.NewDecoder(req.Body).Decode(&protoReq.C); err != nil {
return nil, grpc.Errorf(codes.InvalidArgument, "%v", err)
}
var (
val string
ok bool
err error
_ = err
)
val, ok = pathParams["a.str"]
if !ok {
return nil, grpc.Errorf(codes.InvalidArgument, "missing parameter %s", "a.str")
}
err = runtime.PopulateFieldFromPath(&protoReq, "a.str", val)
if err != nil {
return nil, err
}
if err := runtime.PopulateQueryParameters(&protoReq, req.URL.Query(), filter_FlowCombination_RpcPathNestedStream_2); err != nil {
return nil, grpc.Errorf(codes.InvalidArgument, "%v", err)
}
return client.RpcPathNestedStream(ctx, &protoReq)
}
示例4: request_API_CreateRepo_0
func request_API_CreateRepo_0(ctx context.Context, client APIClient, req *http.Request, pathParams map[string]string) (proto.Message, error) {
var protoReq CreateRepoRequest
var (
val string
ok bool
err error
_ = err
)
val, ok = pathParams["repo.name"]
if !ok {
return nil, grpc.Errorf(codes.InvalidArgument, "missing parameter %s", "repo.name")
}
err = runtime.PopulateFieldFromPath(&protoReq, "repo.name", val)
if err != nil {
return nil, err
}
if err := runtime.PopulateQueryParameters(&protoReq, req.URL.Query(), filter_API_CreateRepo_0); err != nil {
return nil, grpc.Errorf(codes.InvalidArgument, "%v", err)
}
return client.CreateRepo(ctx, &protoReq)
}
示例5: GetNode
// GetNode returns a Node given a NodeID.
// - Returns `InvalidArgument` if NodeID is not provided.
// - Returns `NotFound` if the Node is not found.
func (s *Server) GetNode(ctx context.Context, request *api.GetNodeRequest) (*api.GetNodeResponse, error) {
if request.NodeID == "" {
return nil, grpc.Errorf(codes.InvalidArgument, errInvalidArgument.Error())
}
var node *api.Node
s.store.View(func(tx store.ReadTx) {
node = store.GetNode(tx, request.NodeID)
})
if node == nil {
return nil, grpc.Errorf(codes.NotFound, "node %s not found", request.NodeID)
}
if s.raft != nil {
memberlist := s.raft.GetMemberlist()
for _, member := range memberlist {
if member.NodeID == node.ID {
node.ManagerStatus = &api.ManagerStatus{
RaftID: member.RaftID,
Addr: member.Addr,
Leader: member.Status.Leader,
Reachability: member.Status.Reachability,
}
break
}
}
}
return &api.GetNodeResponse{
Node: node,
}, nil
}
示例6: request_FlowCombination_RpcPathSingleNestedRpc_0
func request_FlowCombination_RpcPathSingleNestedRpc_0(ctx context.Context, client FlowCombinationClient, req *http.Request, pathParams map[string]string) (proto.Message, error) {
var protoReq SingleNestedProto
var (
val string
ok bool
err error
_ = err
)
val, ok = pathParams["a.str"]
if !ok {
return nil, grpc.Errorf(codes.InvalidArgument, "missing parameter %s", "a.str")
}
err = runtime.PopulateFieldFromPath(&protoReq, "a.str", val)
if err != nil {
return nil, err
}
if err := runtime.PopulateQueryParameters(&protoReq, req.URL.Query(), filter_FlowCombination_RpcPathSingleNestedRpc_0); err != nil {
return nil, grpc.Errorf(codes.InvalidArgument, "%v", err)
}
return client.RpcPathSingleNestedRpc(ctx, &protoReq)
}
示例7: TestRegistryAdminClientListGames
func TestRegistryAdminClientListGames(t *testing.T) {
connectRegistryAdminClient()
tests := []struct {
p *apipb.GetGameReleaseRequest
err error
}{
{
p: &apipb.GetGameReleaseRequest{
GameId: "76b30f8c0c96db0001aa911f",
Version: "2.2.2",
State: 1,
},
err: grpc.Errorf(2, "No data found"),
},
{
p: &apipb.GetGameReleaseRequest{},
err: grpc.Errorf(2, "invalid id"),
},
}
for i, tt := range tests {
_, err := registryClient.GetRelease(context.Background(), tt.p)
if err != tt.err {
t.Fatalf("case %d, expected %v, got %v", i, tt.err, err)
}
}
}
示例8: request_ABitOfEverythingService_Update_0
func request_ABitOfEverythingService_Update_0(ctx context.Context, client ABitOfEverythingServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, error) {
var protoReq ABitOfEverything
if err := json.NewDecoder(req.Body).Decode(&protoReq); err != nil {
return nil, grpc.Errorf(codes.InvalidArgument, "%v", err)
}
var (
val string
ok bool
err error
_ = err
)
val, ok = pathParams["uuid"]
if !ok {
return nil, grpc.Errorf(codes.InvalidArgument, "missing parameter %s", "uuid")
}
protoReq.Uuid, err = runtime.String(val)
if err != nil {
return nil, err
}
return client.Update(ctx, &protoReq)
}
示例9: TestRegistryAdminClientGet
//admin-client
func TestRegistryAdminClientGet(t *testing.T) {
connectRegistryAdminClient()
tests := []struct {
p *apipb.GetGameRequest
err error
}{
{
p: &apipb.GetGameRequest{
UniqueName: "sample-otsimo-game-1",
},
},
{
p: &apipb.GetGameRequest{
UniqueName: "myGameYeah1",
},
err: grpc.Errorf(2, "No data found"),
},
{
p: &apipb.GetGameRequest{},
err: grpc.Errorf(2, "No data found"),
},
}
for i, tt := range tests {
_, err := registryClient.Get(context.Background(), tt.p)
if err != tt.err {
t.Fatalf("case %d, expected %v, got %v", i, tt.err, err)
}
}
}
示例10: TestRegistryAdminClientChangeReleaseState
func TestRegistryAdminClientChangeReleaseState(t *testing.T) {
connectRegistryAdminClient()
tests := []struct {
p *apipb.ValidateRequest
err error
}{
{
p: &apipb.ValidateRequest{
GameId: "56b30f8c0c96db0001aa911f",
GameVersion: "0.0.1",
NewState: 3,
},
err: grpc.Errorf(2, "No data found"),
},
{
p: &apipb.ValidateRequest{},
err: grpc.Errorf(2, "invalid id"),
},
}
for i, tt := range tests {
_, err := registryClient.ChangeReleaseState(context.Background(), tt.p)
if err != tt.err {
t.Fatalf("case %d, expected %v, got %v", i, tt.err, err)
}
}
}
示例11: Node
// handleNodeStatus handles GET requests for a single node's status.
func (s *statusServer) Node(
ctx context.Context, req *serverpb.NodeRequest,
) (*status.NodeStatus, error) {
ctx = s.AnnotateCtx(ctx)
nodeID, _, err := s.parseNodeID(req.NodeId)
if err != nil {
return nil, grpc.Errorf(codes.InvalidArgument, err.Error())
}
key := keys.NodeStatusKey(nodeID)
b := &client.Batch{}
b.Get(key)
if err := s.db.Run(ctx, b); err != nil {
log.Error(ctx, err)
return nil, grpc.Errorf(codes.Internal, err.Error())
}
var nodeStatus status.NodeStatus
if err := b.Results[0].Rows[0].ValueProto(&nodeStatus); err != nil {
err = errors.Errorf("could not unmarshal NodeStatus from %s: %s", key, err)
log.Error(ctx, err)
return nil, grpc.Errorf(codes.Internal, err.Error())
}
return &nodeStatus, nil
}
示例12: Nodes
// Nodes returns all node statuses.
func (s *statusServer) Nodes(
ctx context.Context, req *serverpb.NodesRequest,
) (*serverpb.NodesResponse, error) {
ctx = s.AnnotateCtx(ctx)
startKey := keys.StatusNodePrefix
endKey := startKey.PrefixEnd()
b := &client.Batch{}
b.Scan(startKey, endKey)
if err := s.db.Run(ctx, b); err != nil {
log.Error(ctx, err)
return nil, grpc.Errorf(codes.Internal, err.Error())
}
rows := b.Results[0].Rows
resp := serverpb.NodesResponse{
Nodes: make([]status.NodeStatus, len(rows)),
}
for i, row := range rows {
if err := row.ValueProto(&resp.Nodes[i]); err != nil {
log.Error(ctx, err)
return nil, grpc.Errorf(codes.Internal, err.Error())
}
}
return &resp, nil
}
示例13: AllReleases
func (r *RegistryServer) AllReleases(ctx context.Context, in *apipb.GetGameRequest) (*apipb.AllGameReleases, error) {
log.Infof("grpc:AllReleases(): %+v", in)
repo := r.server.DB.GetGameReleaseRepo()
gameID := in.GameId
if len(gameID) == 0 {
g, err := r.server.DB.GetGameRepo().GetGameWithUniqueId(in.UniqueName)
if err != nil {
return nil, grpc.Errorf(codes.NotFound, "game not found")
}
gameID = g.Id
}
list, err := repo.All(gameID)
if err != nil {
return nil, grpc.Errorf(codes.Internal, "failed to get releases, %v", err)
}
res := &apipb.AllGameReleases{
GameId: gameID,
Releases: make([]*apipb.AllGameReleases_MiniRelease, len(list)),
}
for i, r := range list {
res.Releases[i] = &apipb.AllGameReleases_MiniRelease{
Version: r.Version,
ReleasedAt: r.ReleasedAt,
ReleaseState: r.ReleaseState,
}
}
return res, nil
}
示例14: request_ChannelList_Update_0
func request_ChannelList_Update_0(ctx context.Context, marshaler runtime.Marshaler, client ChannelListClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq UpdateChannelListRequest
var metadata runtime.ServerMetadata
if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil {
return nil, metadata, grpc.Errorf(codes.InvalidArgument, "%v", err)
}
var (
val string
ok bool
err error
_ = err
)
val, ok = pathParams["id"]
if !ok {
return nil, metadata, grpc.Errorf(codes.InvalidArgument, "missing parameter %s", "id")
}
protoReq.Id, err = runtime.Int64(val)
if err != nil {
return nil, metadata, err
}
msg, err := client.Update(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
return msg, metadata, err
}
示例15: Login
func (as *authServer) Login(ctx context.Context, request *pb.LoginRequest) (*pb.LoginResponse, error) {
user, err := getUser(db, request.Username)
if err != nil {
return nil, err
}
err = bcrypt.CompareHashAndPassword([]byte(user.PasswordHash), []byte(request.Password))
if err != nil {
return nil, grpc.Errorf(codes.PermissionDenied, "")
}
token := jwt.New(jwt.SigningMethodRS256)
token.Claims["exp"] = time.Now().Add(time.Hour * 72).Unix()
token.Claims["admin"] = user.IsAdmin
token.Claims["iss"] = "auth.service"
token.Claims["iat"] = time.Now().Unix()
token.Claims["email"] = user.Email
token.Claims["sub"] = user.Username
tokenString, err := token.SignedString(as.jwtPrivatekey)
if err != nil {
return nil, grpc.Errorf(codes.Internal, err.Error())
}
return &pb.LoginResponse{tokenString}, nil
}