本文整理汇总了Golang中google/golang.org/grpc.Errorf函数的典型用法代码示例。如果您正苦于以下问题:Golang Errorf函数的具体用法?Golang Errorf怎么用?Golang Errorf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Errorf函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)
}
}
}
开发者ID:otsimo,项目名称:integration-tests,代码行数:25,代码来源:apipb_test.go
示例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,
}
}
开发者ID:HuKeping,项目名称:docker,代码行数:27,代码来源:health.pb.go
示例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)
}
开发者ID:JohanSJA,项目名称:grpc-gateway,代码行数:31,代码来源:flow_combination.pb.gw.go
示例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)
}
开发者ID:angelabier1,项目名称:pachyderm,代码行数:27,代码来源:pfs.pb.gw.go
示例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
}
开发者ID:SUSE,项目名称:docker.mirror,代码行数:35,代码来源:node.go
示例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)
}
开发者ID:JohanSJA,项目名称:grpc-gateway,代码行数:27,代码来源:flow_combination.pb.gw.go
示例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)
}
}
}
开发者ID:otsimo,项目名称:integration-tests,代码行数:27,代码来源:registry_test.go
示例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)
}
开发者ID:floridoo,项目名称:grpc-gateway,代码行数:27,代码来源:a_bit_of_everything.pb.gw.go
示例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)
}
}
}
开发者ID:otsimo,项目名称:integration-tests,代码行数:31,代码来源:registry_test.go
示例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)
}
}
}
开发者ID:otsimo,项目名称:integration-tests,代码行数:27,代码来源:registry_test.go
示例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
}
开发者ID:knz,项目名称:cockroach,代码行数:26,代码来源:status.go
示例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
}
开发者ID:knz,项目名称:cockroach,代码行数:27,代码来源:status.go
示例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
}
开发者ID:otsimo,项目名称:distribution,代码行数:29,代码来源:grpc_server.go
示例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
}
开发者ID:yuseunghyuk,项目名称:loraserver,代码行数:30,代码来源:channelList.pb.gw.go
示例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
}
开发者ID:kelseyhightower,项目名称:grpc-hello-service,代码行数:25,代码来源:login.go
示例16: Query
// Query is an endpoint that returns data for one or more metrics over a
// specific time span.
func (s *Server) Query(ctx context.Context, request *tspb.TimeSeriesQueryRequest) (*tspb.TimeSeriesQueryResponse, error) {
if len(request.Queries) == 0 {
return nil, grpc.Errorf(codes.InvalidArgument, "Queries cannot be empty")
}
response := tspb.TimeSeriesQueryResponse{
Results: make([]tspb.TimeSeriesQueryResponse_Result, 0, len(request.Queries)),
}
for _, q := range request.Queries {
datapoints, sources, err := s.db.Query(q, Resolution10s, request.StartNanos, request.EndNanos)
if err != nil {
return nil, grpc.Errorf(codes.Internal, err.Error())
}
result := tspb.TimeSeriesQueryResponse_Result{
Query: q,
Datapoints: datapoints,
}
// TODO(tamird): Remove this (and all other) explicit setting of defaults.
// It is currently required because the client side doesn't know about
// proto defaults.
result.SourceAggregator = q.GetSourceAggregator().Enum()
result.Downsampler = q.GetDownsampler().Enum()
result.Derivative = q.GetDerivative().Enum()
result.Sources = sources
response.Results = append(response.Results, result)
}
return &response, nil
}
开发者ID:CubeLite,项目名称:cockroach,代码行数:32,代码来源:server.go
示例17: Sign
//Sign signs a message and returns the signature using a private key associate with the KeyID from the SignatureRequest
func (s *SignerServer) Sign(ctx context.Context, sr *pb.SignatureRequest) (*pb.Signature, error) {
tufKey, service, err := FindKeyByID(s.CryptoServices, sr.KeyID)
logger := ctxu.GetLogger(ctx)
if err != nil {
logger.Errorf("Sign: key %s not found", sr.KeyID.ID)
return nil, grpc.Errorf(codes.NotFound, "key %s not found", sr.KeyID.ID)
}
privKey, _, err := service.GetPrivateKey(tufKey.ID())
if err != nil {
logger.Errorf("Sign: key %s not found", sr.KeyID.ID)
return nil, grpc.Errorf(codes.NotFound, "key %s not found", sr.KeyID.ID)
}
sig, err := privKey.Sign(rand.Reader, sr.Content, nil)
if err != nil {
logger.Errorf("Sign: signing failed for KeyID %s on hash %s", sr.KeyID.ID, sr.Content)
return nil, grpc.Errorf(codes.Internal, "Signing failed for KeyID %s on hash %s", sr.KeyID.ID, sr.Content)
}
logger.Info("Sign: Signed ", string(sr.Content), " with KeyID ", sr.KeyID.ID)
signature := &pb.Signature{
KeyInfo: &pb.KeyInfo{
KeyID: &pb.KeyID{ID: tufKey.ID()},
Algorithm: &pb.Algorithm{Algorithm: tufKey.Algorithm()},
},
Algorithm: &pb.Algorithm{Algorithm: privKey.SignatureAlgorithm().String()},
Content: sig,
}
return signature, nil
}
开发者ID:mbentley,项目名称:notary,代码行数:35,代码来源:rpc_api.go
示例18: RemoveNode
// RemoveNode removes a Node referenced by NodeID with the given NodeSpec.
// - Returns NotFound if the Node is not found.
// - Returns FailedPrecondition if the Node has manager role (and is part of the memberlist) or is not shut down.
// - Returns InvalidArgument if NodeID or NodeVersion is not valid.
// - Returns an error if the delete fails.
func (s *Server) RemoveNode(ctx context.Context, request *api.RemoveNodeRequest) (*api.RemoveNodeResponse, error) {
if request.NodeID == "" {
return nil, grpc.Errorf(codes.InvalidArgument, errInvalidArgument.Error())
}
err := s.store.Update(func(tx store.Tx) error {
node := store.GetNode(tx, request.NodeID)
if node == nil {
return grpc.Errorf(codes.NotFound, "node %s not found", request.NodeID)
}
if node.Spec.Role == api.NodeRoleManager {
if s.raft == nil {
return grpc.Errorf(codes.FailedPrecondition, "node %s is a manager but cannot access node information from the raft memberlist", request.NodeID)
}
if member := s.raft.GetMemberByNodeID(request.NodeID); member != nil {
return grpc.Errorf(codes.FailedPrecondition, "node %s is a cluster manager and is a member of the raft cluster. It must be demoted to worker before removal", request.NodeID)
}
}
if !request.Force && node.Status.State == api.NodeStatus_READY {
return grpc.Errorf(codes.FailedPrecondition, "node %s is not down and can't be removed", request.NodeID)
}
return store.DeleteNode(tx, request.NodeID)
})
if err != nil {
return nil, err
}
return &api.RemoveNodeResponse{}, nil
}
开发者ID:SUSE,项目名称:docker.mirror,代码行数:33,代码来源:node.go
示例19: validateRestartPolicy
func validateRestartPolicy(rp *api.RestartPolicy) error {
if rp == nil {
return nil
}
if rp.Delay != nil {
delay, err := ptypes.Duration(rp.Delay)
if err != nil {
return err
}
if delay < 0 {
return grpc.Errorf(codes.InvalidArgument, "TaskSpec: restart-delay cannot be negative")
}
}
if rp.Window != nil {
win, err := ptypes.Duration(rp.Window)
if err != nil {
return err
}
if win < 0 {
return grpc.Errorf(codes.InvalidArgument, "TaskSpec: restart-window cannot be negative")
}
}
return nil
}
开发者ID:ChristianKniep,项目名称:swarmkit,代码行数:27,代码来源:service.go
示例20: request_FlowCombination_RpcBodyStream_6
func request_FlowCombination_RpcBodyStream_6(ctx context.Context, client FlowCombinationClient, req *http.Request, pathParams map[string]string) (FlowCombination_RpcBodyStreamClient, error) {
var protoReq NonEmptyProto
var (
val string
ok bool
err error
_ = err
)
val, ok = pathParams["a"]
if !ok {
return nil, grpc.Errorf(codes.InvalidArgument, "missing parameter %s", "a")
}
protoReq.A, err = runtime.String(val)
if err != nil {
return nil, err
}
if err := runtime.PopulateQueryParameters(&protoReq, req.URL.Query(), filter_FlowCombination_RpcBodyStream_6); err != nil {
return nil, grpc.Errorf(codes.InvalidArgument, "%v", err)
}
return client.RpcBodyStream(ctx, &protoReq)
}
开发者ID:JohanSJA,项目名称:grpc-gateway,代码行数:27,代码来源:flow_combination.pb.gw.go
注:本文中的google/golang.org/grpc.Errorf函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论