-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstream.go
60 lines (54 loc) · 1.39 KB
/
stream.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
package getstream
type Stream struct {
*Client
chat *ChatClient
video *VideoClient
}
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
}