當前位置: 首頁>>代碼示例>>Golang>>正文


Golang grpc.Errorf函數代碼示例

本文整理匯總了Golang中github.com/coreos/etcd/Godeps/_workspace/src/google/golang.org/grpc.Errorf函數的典型用法代碼示例。如果您正苦於以下問題:Golang Errorf函數的具體用法?Golang Errorf怎麽用?Golang Errorf使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了Errorf函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: testFailedEmptyUnary

func testFailedEmptyUnary(t *testing.T, e env) {
	s, cc := setUp(math.MaxUint32, e)
	tc := testpb.NewTestServiceClient(cc)
	defer tearDown(s, cc)
	ctx := metadata.NewContext(context.Background(), testMetadata)
	if _, err := tc.EmptyCall(ctx, &testpb.Empty{}); err != grpc.Errorf(codes.DataLoss, "got extra metadata") {
		t.Fatalf("TestService/EmptyCall(_, _) = _, %v, want _, %v", err, grpc.Errorf(codes.DataLoss, "got extra metadata"))
	}
}
開發者ID:CNDonny,項目名稱:scope,代碼行數:9,代碼來源:end2end_test.go

示例2: testHealthCheckServingStatus

func testHealthCheckServingStatus(t *testing.T, e env) {
	hs := health.NewHealthServer()
	s, addr := serverSetUp(t, hs, math.MaxUint32, nil, nil, e)
	cc := clientSetUp(t, addr, nil, nil, "", e)
	defer tearDown(s, cc)
	out, err := healthCheck(1*time.Second, cc, "")
	if err != nil {
		t.Fatalf("Health/Check(_, _) = _, %v, want _, <nil>", err)
	}
	if out.Status != healthpb.HealthCheckResponse_SERVING {
		t.Fatalf("Got the serving status %v, want SERVING", out.Status)
	}
	if _, err := healthCheck(1*time.Second, cc, "grpc.health.v1alpha.Health"); err != grpc.Errorf(codes.NotFound, "unknown service") {
		t.Fatalf("Health/Check(_, _) = _, %v, want _, error code %d", err, codes.NotFound)
	}
	hs.SetServingStatus("grpc.health.v1alpha.Health", healthpb.HealthCheckResponse_SERVING)
	out, err = healthCheck(1*time.Second, cc, "grpc.health.v1alpha.Health")
	if err != nil {
		t.Fatalf("Health/Check(_, _) = _, %v, want _, <nil>", err)
	}
	if out.Status != healthpb.HealthCheckResponse_SERVING {
		t.Fatalf("Got the serving status %v, want SERVING", out.Status)
	}
	hs.SetServingStatus("grpc.health.v1alpha.Health", healthpb.HealthCheckResponse_NOT_SERVING)
	out, err = healthCheck(1*time.Second, cc, "grpc.health.v1alpha.Health")
	if err != nil {
		t.Fatalf("Health/Check(_, _) = _, %v, want _, <nil>", err)
	}
	if out.Status != healthpb.HealthCheckResponse_NOT_SERVING {
		t.Fatalf("Got the serving status %v, want NOT_SERVING", out.Status)
	}

}
開發者ID:rtewalt,項目名稱:etcd,代碼行數:33,代碼來源:end2end_test.go

示例3: StreamingOutputCall

func (s *testServer) StreamingOutputCall(args *testpb.StreamingOutputCallRequest, stream testpb.TestService_StreamingOutputCallServer) error {
	if md, ok := metadata.FromContext(stream.Context()); ok {
		// For testing purpose, returns an error if there is attached metadata.
		if len(md) > 0 {
			return grpc.Errorf(codes.DataLoss, "got extra metadata")
		}
	}
	cs := args.GetResponseParameters()
	for _, c := range cs {
		if us := c.GetIntervalUs(); us > 0 {
			time.Sleep(time.Duration(us) * time.Microsecond)
		}

		payload, err := newPayload(args.GetResponseType(), c.GetSize())
		if err != nil {
			return err
		}

		if err := stream.Send(&testpb.StreamingOutputCallResponse{
			Payload: payload,
		}); err != nil {
			return err
		}
	}
	return nil
}
開發者ID:rtewalt,項目名稱:etcd,代碼行數:26,代碼來源:end2end_test.go

示例4: EmptyCall

func (s *testServer) EmptyCall(ctx context.Context, in *testpb.Empty) (*testpb.Empty, error) {
	if _, ok := metadata.FromContext(ctx); ok {
		// For testing purpose, returns an error if there is attached metadata.
		return nil, grpc.Errorf(codes.DataLoss, "got extra metadata")
	}
	return new(testpb.Empty), nil
}
開發者ID:CNDonny,項目名稱:scope,代碼行數:7,代碼來源:end2end_test.go

示例5: testHealthCheckOff

func testHealthCheckOff(t *testing.T, e env) {
	s, addr := serverSetUp(t, nil, math.MaxUint32, nil, nil, e)
	cc := clientSetUp(t, addr, nil, nil, "", e)
	defer tearDown(s, cc)
	if _, err := healthCheck(1*time.Second, cc, ""); err != grpc.Errorf(codes.Unimplemented, "unknown service grpc.health.v1alpha.Health") {
		t.Fatalf("Health/Check(_, _) = _, %v, want _, error code %d", err, codes.Unimplemented)
	}
}
開發者ID:rtewalt,項目名稱:etcd,代碼行數:8,代碼來源:end2end_test.go

示例6: testHealthCheckOnFailure

func testHealthCheckOnFailure(t *testing.T, e env) {
	hs := health.NewHealthServer()
	hs.SetServingStatus("grpc.health.v1alpha.HealthCheck", 1)
	s, addr := serverSetUp(t, hs, math.MaxUint32, nil, nil, e)
	cc := clientSetUp(t, addr, nil, nil, "", e)
	defer tearDown(s, cc)
	if _, err := healthCheck(0*time.Second, cc, "grpc.health.v1alpha.Health"); err != grpc.Errorf(codes.DeadlineExceeded, "context deadline exceeded") {
		t.Fatalf("Health/Check(_, _) = _, %v, want _, error code %d", err, codes.DeadlineExceeded)
	}
}
開發者ID:rtewalt,項目名稱:etcd,代碼行數:10,代碼來源:end2end_test.go

示例7: togRPCError

func togRPCError(err error) error {
	switch err {
	case storage.ErrCompacted:
		return ErrCompacted
	case storage.ErrFutureRev:
		return ErrFutureRev
	// TODO: handle error from raft and timeout
	default:
		return grpc.Errorf(codes.Unknown, err.Error())
	}
}
開發者ID:pj2,項目名稱:etcd,代碼行數:11,代碼來源:key.go

示例8: MemberRemove

func (cs *ClusterServer) MemberRemove(ctx context.Context, r *pb.MemberRemoveRequest) (*pb.MemberRemoveResponse, error) {
	err := cs.server.RemoveMember(ctx, r.ID)
	switch {
	case err == etcdserver.ErrIDRemoved:
		fallthrough
	case err == etcdserver.ErrIDNotFound:
		return nil, ErrMemberNotFound
	case err != nil:
		return nil, grpc.Errorf(codes.Internal, err.Error())
	}

	return &pb.MemberRemoveResponse{Header: cs.header()}, nil
}
開發者ID:lrita,項目名稱:etcd,代碼行數:13,代碼來源:member.go

示例9: togRPCError

func togRPCError(err error) error {
	switch err {
	case storage.ErrCompacted:
		return ErrCompacted
	case storage.ErrFutureRev:
		return ErrFutureRev
	case lease.ErrLeaseNotFound:
		return ErrLeaseNotFound
	// TODO: handle error from raft and timeout
	default:
		return grpc.Errorf(codes.Internal, err.Error())
	}
}
開發者ID:jianghaishanyue,項目名稱:etcd,代碼行數:13,代碼來源:key.go

示例10: testFailedServerStreaming

func testFailedServerStreaming(t *testing.T, e env) {
	s, cc := setUp(math.MaxUint32, e)
	tc := testpb.NewTestServiceClient(cc)
	defer tearDown(s, cc)
	respParam := make([]*testpb.ResponseParameters, len(respSizes))
	for i, s := range respSizes {
		respParam[i] = &testpb.ResponseParameters{
			Size: proto.Int32(int32(s)),
		}
	}
	req := &testpb.StreamingOutputCallRequest{
		ResponseType:       testpb.PayloadType_COMPRESSABLE.Enum(),
		ResponseParameters: respParam,
	}
	ctx := metadata.NewContext(context.Background(), testMetadata)
	stream, err := tc.StreamingOutputCall(ctx, req)
	if err != nil {
		t.Fatalf("%v.StreamingOutputCall(_) = _, %v, want <nil>", tc, err)
	}
	if _, err := stream.Recv(); err != grpc.Errorf(codes.DataLoss, "got extra metadata") {
		t.Fatalf("%v.Recv() = _, %v, want _, %v", stream, err, grpc.Errorf(codes.DataLoss, "got extra metadata"))
	}
}
開發者ID:CNDonny,項目名稱:scope,代碼行數:23,代碼來源:end2end_test.go

示例11: togRPCError

func togRPCError(err error) error {
	switch err {
	case storage.ErrCompacted:
		return rpctypes.ErrCompacted
	case storage.ErrFutureRev:
		return rpctypes.ErrFutureRev
	case lease.ErrLeaseNotFound:
		return rpctypes.ErrLeaseNotFound
	// TODO: handle error from raft and timeout
	case etcdserver.ErrRequestTooLarge:
		return rpctypes.ErrRequestTooLarge
	default:
		return grpc.Errorf(codes.Internal, err.Error())
	}
}
開發者ID:siddontang,項目名稱:etcd,代碼行數:15,代碼來源:key.go

示例12: EmptyCall

func (s *testServer) EmptyCall(ctx context.Context, in *testpb.Empty) (*testpb.Empty, error) {
	if md, ok := metadata.FromContext(ctx); ok {
		// For testing purpose, returns an error if there is attached metadata other than
		// the user agent set by the client application.
		if _, ok := md["user-agent"]; !ok {
			return nil, grpc.Errorf(codes.DataLoss, "got extra metadata")
		}
		var str []string
		for _, entry := range md["user-agent"] {
			str = append(str, "ua", entry)
		}
		grpc.SendHeader(ctx, metadata.Pairs(str...))
	}
	return new(testpb.Empty), nil
}
開發者ID:rtewalt,項目名稱:etcd,代碼行數:15,代碼來源:end2end_test.go

示例13: Check

func (s *HealthServer) Check(ctx context.Context, in *healthpb.HealthCheckRequest) (*healthpb.HealthCheckResponse, error) {
	s.mu.Lock()
	defer s.mu.Unlock()
	if in.Service == "" {
		// check the server overall health status.
		return &healthpb.HealthCheckResponse{
			Status: healthpb.HealthCheckResponse_SERVING,
		}, nil
	}
	if status, ok := s.statusMap[in.Service]; ok {
		return &healthpb.HealthCheckResponse{
			Status: status,
		}, nil
	}
	return nil, grpc.Errorf(codes.NotFound, "unknown service")
}
開發者ID:rtewalt,項目名稱:etcd,代碼行數:16,代碼來源:health.go

示例14: MemberUpdate

func (cs *ClusterServer) MemberUpdate(ctx context.Context, r *pb.MemberUpdateRequest) (*pb.MemberUpdateResponse, error) {
	m := etcdserver.Member{
		ID:             types.ID(r.ID),
		RaftAttributes: etcdserver.RaftAttributes{PeerURLs: r.PeerURLs},
	}
	err := cs.server.UpdateMember(ctx, m)
	switch {
	case err == etcdserver.ErrPeerURLexists:
		return nil, ErrPeerURLExist
	case err == etcdserver.ErrIDNotFound:
		return nil, ErrMemberNotFound
	case err != nil:
		return nil, grpc.Errorf(codes.Internal, err.Error())
	}

	return &pb.MemberUpdateResponse{Header: cs.header()}, nil
}
開發者ID:lrita,項目名稱:etcd,代碼行數:17,代碼來源:member.go

示例15: MemberAdd

func (cs *ClusterServer) MemberAdd(ctx context.Context, r *pb.MemberAddRequest) (*pb.MemberAddResponse, error) {
	urls, err := types.NewURLs(r.PeerURLs)
	if err != nil {
		return nil, ErrMemberBadURLs
	}

	now := time.Now()
	m := etcdserver.NewMember("", urls, "", &now)
	err = cs.server.AddMember(ctx, *m)
	switch {
	case err == etcdserver.ErrIDExists:
		return nil, ErrMemberExist
	case err == etcdserver.ErrPeerURLexists:
		return nil, ErrPeerURLExist
	case err != nil:
		return nil, grpc.Errorf(codes.Internal, err.Error())
	}

	return &pb.MemberAddResponse{
		Header: cs.header(),
		Member: &pb.Member{ID: uint64(m.ID), IsLeader: m.ID == cs.server.Leader(), PeerURLs: m.PeerURLs},
	}, nil
}
開發者ID:lrita,項目名稱:etcd,代碼行數:23,代碼來源:member.go


注:本文中的github.com/coreos/etcd/Godeps/_workspace/src/google/golang.org/grpc.Errorf函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。