-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.go
43 lines (39 loc) · 1.05 KB
/
util.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
package pipe
import (
"github.com/pinealctx/neptune/syncx/pipe/q"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
var (
//ErrNoHandler -- no message handler
ErrNoHandler = status.Error(codes.Unimplemented, "no.req.handler")
//ErrQueueFull -- msg queue is full
ErrQueueFull = status.Error(codes.ResourceExhausted, "req.queue.full")
//ErrQueueClosed -- msg queue closed
ErrQueueClosed = status.Error(codes.Unavailable, "req.queue.closed")
//ErrInvalidParam -- invalid msg param
ErrInvalidParam = status.Error(codes.InvalidArgument, "invalid.req.param")
//ErrInvalidRsp -- invalid result
ErrInvalidRsp = status.Error(codes.Internal, "invalid.rsp.msg")
)
// ConvertQueueErr convert msg queue error
func ConvertQueueErr(err error) error {
if err == nil {
return nil
}
if err == q.ErrReqQFull {
return ErrQueueFull
}
if err == q.ErrClosed {
return ErrQueueClosed
}
return err
}
// NormalizeSlotIndex slot index
func NormalizeSlotIndex(index int, slotSize int) int {
if index < 0 {
index = -index
}
index %= slotSize
return index
}