-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathstream.go
More file actions
78 lines (70 loc) · 1.75 KB
/
stream.go
File metadata and controls
78 lines (70 loc) · 1.75 KB
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
package getstream
type Stream struct {
*Client
chat *ChatClient
video *VideoClient
feeds *FeedsClient
moderation *ModerationClient
}
func NewClientFromEnvVars(options ...ClientOption) (*Stream, error) {
client, err := newClientFromEnvVars(options...)
if err != nil {
return nil, err
}
return &Stream{
Client: client,
}, nil
}
func NewClient(apiKey, apiSecret string, options ...ClientOption) (*Stream, error) {
client, err := newClient(apiKey, apiSecret, options...)
if err != nil {
return nil, err
}
return &Stream{
Client: client,
}, nil
}
// CreateToken generates a token for a given user ID, with optional claims.
//
// Parameters:
// - userID (string): The unique identifier of the user for whom the token is being created.
// - claims (*Claims): A pointer to a Claims struct containing optional parameters.
//
// Returns:
// - (string): The generated JWT token.
// - (error): An error object if token creation fails.
//
// token, err := client.CreateToken("userID", getstream.WithExpiration(time.Hour))
func (s *Stream) CreateToken(userID string, opts ...TokenOption) (string, error) {
o := tokenOptions{}
for _, opt := range opts {
opt(&o)
}
return s.createToken(userID, o.claims, o.expiration)
}
func (s *Stream) Chat() *ChatClient {
if s.chat == nil {
s.chat = NewChatClient(s.Client)
}
return s.chat
}
func (s *Stream) Video() *VideoClient {
if s.video == nil {
s.video = NewVideoClient(s.Client)
}
return s.video
}
// Feeds client
func (s *Stream) Feeds() *FeedsClient {
if s.feeds == nil {
s.feeds = NewFeedsClient(s.Client)
}
return s.feeds
}
// Moderation client
func (s *Stream) Moderation() *ModerationClient {
if s.moderation == nil {
s.moderation = NewModerationClient(s.Client)
}
return s.moderation
}