go-twitch/api/conduit/create_conduits.go

39 lines
816 B
Go

package conduit
import (
"context"
"encoding/json"
"fmt"
"net/http"
"net/url"
)
type CreateConduitsResponse struct {
Data []ConduitData `json:"data"`
}
// Creates a new conduit.
//
// Requires an app access token.
func (c *Conduit) CreateConduits(ctx context.Context, shareCount int) (*CreateConduitsResponse, error) {
endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "eventsub/conduits", RawQuery: "share_count=" + fmt.Sprint(shareCount)})
req, err := http.NewRequestWithContext(ctx, http.MethodPost, 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 CreateConduitsResponse
if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
return nil, err
}
return &data, nil
}