-
Notifications
You must be signed in to change notification settings - Fork 11
/
common.go
77 lines (62 loc) · 1.64 KB
/
common.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
// GTRS (Go Typed Redis Streams) is a library for easily reading Redis streams with or without consumer groups.
// See https://github.com/dranikpg/gtrs for a quick tutorial.
package gtrs
import (
"fmt"
"github.com/redis/go-redis/v9"
)
// A generic message with an ID, stream, data and an optional error.
type Message[T any] struct {
ID string
Stream string
Err error
Data T
}
// fetchMessage is used for sending a redis.XMessage together with its corresponding stream.
// Used in consumer fetchloops.
type fetchMessage struct {
stream string
message redis.XMessage
}
// innerAckError is sent by ackLoop and carries the id of the failed ack request and its cause.
type innerAckError struct {
InnerAck
cause error
}
type InnerAck struct {
ID string
Stream string
}
// ReadError indicates an erorr with the redis client.
//
// After a ReadError was returned from a consumer, it'll close its main channel.
type ReadError struct {
Err error
}
func (ce ReadError) Unwrap() error {
return ce.Err
}
func (ce ReadError) Error() string {
return fmt.Sprintf("read error: %v", ce.Err)
}
// AckError indicates that an acknowledgement request failed.
type AckError struct {
Err error
}
func (ae AckError) Unwrap() error {
return ae.Err
}
func (ae AckError) Error() string {
return fmt.Sprintf("acknowledge error: cause: %v", ae.Err)
}
// ParseError indicates an error during parsing.
type ParseError struct {
Data map[string]interface{} // raw data returned by the redis client
Err error
}
func (pe ParseError) Unwrap() error {
return pe.Err
}
func (pe ParseError) Error() string {
return fmt.Sprintf("parsing error: cause: %v", pe.Err)
}