The Livepeer Go library provides convenient access to the Livepeer Studio API from applications written in Golang.
For full documentation and examples, please visit docs.livepeer.org.
Install the package:
go get github.com/livepeer/livepeer-go
The library needs to be configured with your Livepeer Studio account's API key, which is available in the Studio Dashboard.
package main
import(
"context"
"log"
livepeer "github.com/livepeer/livepeer-go"
"github.com/livepeer/livepeer-go/models/components"
)
func main() {
s := livepeer.New(
livepeer.WithSecurity(""),
)
ctx := context.Background()
res, err := s.Stream.GetAll(ctx)
if err != nil {
log.Fatal(err)
}
if res.Data != nil {
// handle response
}
}
- PostStream - Create a stream
- GetStream - Retrieve streams
- GetStreamID - Retrieve a stream
- PatchStreamID - Update a stream
- DeleteStreamID - Delete a stream
- DeleteStreamIDTerminate - Terminates a live stream
- PostStreamIDStartPull - Start ingest for a pull stream
- GetMultistreamTarget - Retrieve Multistream Targets
- PostMultistreamTarget - Create a multistream target
- GetMultistreamTargetID - Retrieve a multistream target
- PatchMultistreamTargetID - Update Multistream Target
- DeleteMultistreamTargetID - Delete a multistream target
- GetWebhook - Retrieve a Webhook
- PostWebhook - Create a webhook
- GetWebhookID - Retrieve a webhook
- PutWebhookID - Update a webhook
- DeleteWebhookID - Delete a webhook
- GetWebhookIDLog - Retrieve webhook logs
- GetWebhookIDLogLogID - Retrieve a webhook log
- PostWebhookIDLogLogIDResend - Resend a webhook
- GetAsset - Retrieve assets
- PostAssetRequestUpload - Upload an asset
- PostAssetUploadURL - Upload asset via URL
- GetAssetAssetID - Retrieves an asset
- PatchAssetAssetID - Patch an asset
- DeleteAssetAssetID - Delete an asset
- PostClip - Create a clip
- GetStreamIDClips - Retrieve clips of a livestream
- PostStreamIDCreateMultistreamTarget - Add a multistream target
- DeleteStreamIDMultistreamTargetID - Remove a multistream target
- GetSessionIDClips - Retrieve clips of a session
- PostRoom - Create a room
- GetRoomID - Retrieve a room
- DeleteRoomID - Delete a room
- PostRoomIDEgress - Start room RTMP egress
- DeleteRoomIDEgress - Stop room RTMP egress
- PostRoomIDUser - Create a room user
- GetRoomIDUserUserID - Get user details
- PutRoomIDUserUserID - Update a room user
- DeleteRoomIDUserUserID - Remove a user from the room
- GetDataViewsQuery - Query viewership metrics
- GetDataViewsQueryCreator - Query creator viewership metrics
- GetDataViewsQueryTotalPlaybackID - Query public total views metrics
- GetDataUsageQuery - Query usage metrics
- GetSession - Retrieve sessions
- GetSessionID - Retrieve a session
- GetStreamParentIDSessions - Retrieve Recorded Sessions
- PostAccessControlSigningKey - Create a signing key
- GetAccessControlSigningKey - Retrieves signing keys
- DeleteAccessControlSigningKeyKeyID - Delete Signing Key
- GetAccessControlSigningKeyKeyID - Retrieves a signing key
- PatchAccessControlSigningKeyKeyID - Update a signing key
- GetTask - Retrieve Tasks
- GetTaskTaskID - Retrieve a Task
- PostTranscode - Transcode a video
- GetPlaybackID - Retrieve Playback Info
Handling errors in this SDK should largely match your expectations. All operations return a response object or an error, they will never return both. When specified by the OpenAPI spec document, the SDK will return the appropriate subclass.
Error Object | Status Code | Content Type |
---|---|---|
sdkerrors.Error | 404 | application/json |
sdkerrors.SDKError | 4xx-5xx | / |
package main
import (
"context"
"errors"
livepeer "github.com/livepeer/livepeer-go"
"github.com/livepeer/livepeer-go/models/components"
"github.com/livepeer/livepeer-go/models/sdkerrors"
"log"
)
func main() {
s := livepeer.New(
livepeer.WithSecurity("<YOUR_BEARER_TOKEN_HERE>"),
)
var id string = "<value>"
ctx := context.Background()
res, err := s.GetPlaybackID(ctx, id)
if err != nil {
var e *sdkerrors.Error
if errors.As(err, &e) {
// handle error
log.Fatal(e.Error())
}
var e *sdkerrors.SDKError
if errors.As(err, &e) {
// handle error
log.Fatal(e.Error())
}
}
}
The default server can also be overridden globally using the WithServerURL
option when initializing the SDK client instance. For example:
package main
import (
"context"
livepeer "github.com/livepeer/livepeer-go"
"github.com/livepeer/livepeer-go/models/components"
"log"
)
func main() {
s := livepeer.New(
livepeer.WithServerURL("https://livepeer.studio/api"),
livepeer.WithSecurity("<YOUR_BEARER_TOKEN_HERE>"),
)
ctx := context.Background()
res, err := s.PostStream(ctx, components.NewStreamPayload{
Name: "test_stream",
Record: livepeer.Bool(false),
})
if err != nil {
log.Fatal(err)
}
if res.Stream != nil {
// handle response
}
}
The Go SDK makes API calls that wrap an internal HTTP client. The requirements for the HTTP client are very simple. It must match this interface:
type HTTPClient interface {
Do(req *http.Request) (*http.Response, error)
}
The built-in net/http
client satisfies this interface and a default client based on the built-in is provided by default. To replace this default with a client of your own, you can implement this interface yourself or provide your own client configured as desired. Here's a simple example, which adds a client with a 30 second timeout.
import (
"net/http"
"time"
"github.com/myorg/your-go-sdk"
)
var (
httpClient = &http.Client{Timeout: 30 * time.Second}
sdkClient = sdk.New(sdk.WithClient(httpClient))
)
This can be a convenient way to configure timeouts, cookies, proxies, custom headers, and other low-level configuration.