go-twitch/api/conduit/get_conduit_shards.go

57 lines
1.4 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 conduit
import (
"context"
"encoding/json"
"net/http"
"net/url"
"github.com/google/go-querystring/query"
"go.fifitido.net/twitch/api/types"
)
type GetConduitShardsParams struct {
// Conduit ID.
ConduitID string `url:"conduit_id"`
// Status to filter by.
Status *Status `url:"status,omitempty"`
// The cursor used to get the next page of results. The pagination object in the response contains the cursors value.
Cursor *types.Cursor `url:"cursor,omitempty"`
}
type GetConduitShardsResponse struct {
// List of information about a conduit's shards.
Data []Shard `json:"data"`
// The cursor used to get the next page of results. Use the cursor to set the requests after query parameter.
Pagination types.Pagination `json:"pagination"`
}
// Gets a lists of all shards for a conduit.
//
// Requires an app access token.
func (c *Conduit) GetConduitShards(ctx context.Context, params *GetConduitShardsParams) (*GetConduitShardsResponse, error) {
v, _ := query.Values(params)
endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "eventsub/conduits/shards", RawQuery: v.Encode()})
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 GetConduitShardsResponse
if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
return nil, err
}
return &data, nil
}