-
Notifications
You must be signed in to change notification settings - Fork 4
/
alias.go
89 lines (79 loc) · 2.99 KB
/
alias.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package federation
// Aliases list of types or functions from third-party libraries to minimize the list of imported packages.
import (
"context"
"os"
"sync"
"github.com/cenkalti/backoff/v4"
"github.com/google/cel-go/cel"
"github.com/google/cel-go/common/types"
"golang.org/x/sync/errgroup"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/protoadapt"
)
type (
ErrorGroup = errgroup.Group
ProtoMessage = protoadapt.MessageV1
CELTypeDeclare = cel.Type
CELEnv = cel.Env
CELEnvOption = cel.EnvOption
CELFieldType = types.FieldType
Code = codes.Code
RWMutex = sync.RWMutex
Status = status.Status
)
var (
Getenv = os.Getenv
GRPCErrorf = status.Errorf
NewGRPCStatus = status.New
ErrorGroupWithContext = errgroup.WithContext
NewCELEnv = cel.NewCustomEnv
CELLib = cel.Lib
CELDoubleType = types.DoubleType
CELIntType = types.IntType
CELUintType = types.UintType
CELBoolType = types.BoolType
CELStringType = types.StringType
CELBytesType = types.BytesType
CELObjectType = cel.ObjectType
CELListType = cel.ListType
NewCELListType = types.NewListType
NewCELObjectType = types.NewObjectType
)
const (
OKCode Code = codes.OK
// CancelledCode this is not a typo.
// On proto, it is defined as `CANCELLED`, but in Go's library it is defined as Canceled.
// The name of the code is automatically generated by (*GRPCError).GoGRPCStatusCode in generator/code_generator.go.
// So if the name is different, it will not work. Therefore, the names should be the same as the names on the proto side.
// - Proto: https://github.com/googleapis/googleapis/blob/65277ddce9caa1cfd1a0eb7ab67980fc73d20b50/google/rpc/code.proto#L41
// - Go: https://github.com/grpc/grpc-go/blob/9952aa83979822b5915c3fcb2bb0f60afe55aa7d/codes/codes.go#L45
//nolint:misspell
CancelledCode Code = codes.Canceled
UnknownCode Code = codes.Unknown
InvalidArgumentCode Code = codes.InvalidArgument
DeadlineExceededCode Code = codes.DeadlineExceeded
NotFoundCode Code = codes.NotFound
AlreadyExistsCode Code = codes.AlreadyExists
PermissionDeniedCode Code = codes.PermissionDenied
ResourceExhaustedCode Code = codes.ResourceExhausted
FailedPreconditionCode Code = codes.FailedPrecondition
AbortedCode Code = codes.Aborted
OutOfRangeCode Code = codes.OutOfRange
UnimplementedCode Code = codes.Unimplemented
InternalCode Code = codes.Internal
UnavailableCode Code = codes.Unavailable
DataLossCode Code = codes.DataLoss
UnauthenticatedCode Code = codes.Unauthenticated
)
func BackOffWithMaxRetries(b *BackOff, max uint64) *BackOff {
return &BackOff{
BackOff: backoff.WithMaxRetries(b, max),
}
}
func BackOffWithContext(b *BackOff, ctx context.Context) *BackOff {
return &BackOff{
BackOff: backoff.WithContext(b, ctx),
}
}