go-twitch/api/chat/get_global_chat_badges.go

40 lines
1.1 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package chat
import (
"context"
"encoding/json"
"net/http"
"net/url"
)
type GetGlobalChatBadgesResponse struct {
// The list of chat badges. The list is sorted in ascending order by set_id, and within a set, the list is sorted in ascending order by id.
Data []Badge `json:"data"`
}
// Gets Twitchs list of chat badges, which users may use in any channels chat room.
// For information about chat badges, see Twitch Chat Badges Guide: https://help.twitch.tv/s/article/twitch-chat-badges-guide
//
// Requires an app access token or user access token.
func (c *Chat) GetGlobalChatBadges(ctx context.Context) (*GetGlobalChatBadgesResponse, error) {
endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "chat/badges/global"})
req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil)
if err != nil {
return nil, err
}
res, err := c.client.Do(req)
if err != nil {
return nil, err
}
defer res.Body.Close()
var data GetGlobalChatBadgesResponse
if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
return nil, err
}
return &data, nil
}