forked from saiya/dsps
-
Notifications
You must be signed in to change notification settings - Fork 2
/
channel.go
46 lines (35 loc) · 1.18 KB
/
channel.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
package domain
import (
"context"
"fmt"
"regexp"
)
// ChannelID is ID of the PubSub channel, system-wide unique value
type ChannelID string
//go:generate mockgen -source=${GOFILE} -package=mock -destination=./mock/${GOFILE}
// ChannelProvider provides configured Channel object.
// If given ChannelID is not valid for this server process, returns (nil, domain.ErrInvalidChannel).
type ChannelProvider interface {
Get(id ChannelID) (Channel, error)
GetFileDescriptorPressure() int
JWTClockSkewLeewayMax() Duration
Shutdown(ctx context.Context)
}
// Channel struct holds all objects/information of a channel
type Channel interface {
Expire() Duration
// Note that this method does not check revocation list.
ValidateJwt(ctx context.Context, jwt string) error
SendOutgoingWebhook(ctx context.Context, msg Message) error
}
// see: doc/interface/validation_rule.md
var (
channelIDRegexp = regexp.MustCompile("^[0-9a-z][0-9a-z_-]{0,62}$")
)
// ParseChannelID try to parse ID
func ParseChannelID(str string) (ChannelID, error) {
if !channelIDRegexp.MatchString(str) {
return ChannelID(""), fmt.Errorf("ChannelID must match with %s", channelIDRegexp.String())
}
return ChannelID(str), nil
}