-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcredentials.go
36 lines (31 loc) · 1.08 KB
/
credentials.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
package waterlink
import (
"fmt"
"github.com/gompus/snowflake"
"github.com/lukasl-dev/waterlink/v2/internal"
"net/http"
)
// Credentials is a struct that holds the necessary information to communicate
// with the server.
type Credentials struct {
// Authorization is the password matching the server configuration. This
// is required for the initial handshake.
Authorization string `json:"authorization,omitempty"`
// UserID is the user ID of the bot to play music with. This is required
// to play audio.
UserID snowflake.Snowflake `json:"userId,omitempty"`
// ResumeKey is the key of the session you want to resume. If it is empty,
// a new session will be created.
ResumeKey string `json:"resumeKey,omitempty"`
}
// header creates a http.Header from creds and returns it.
func (creds Credentials) header() http.Header {
h := make(http.Header)
h.Set("Client-Name", fmt.Sprintf("%s/%s", internal.Name, internal.Version))
h.Set("Authorization", creds.Authorization)
h.Set("User-Id", creds.UserID.String())
if creds.ResumeKey != "" {
h.Set("Resume-Key", creds.ResumeKey)
}
return h
}