AIOZ Stream Go client
AIOZ Stream is the video infrastructure for product builders. Lightning fast video APIs for integrating, scaling, and managing on-demand & low latency live streaming features in your app.
Getting started
Installation
go get github.com/AIOZNetwork/aioz-stream-go-clientCode sample
For a more advanced usage you can checkout the rest of the documentation in the docs directory (opens in a new tab)
package main
import (
"context"
"fmt"
"os"
aiozstreamsdk "github.com/AIOZNetwork/aioz-stream-go-client"
)
func main() {
// Connect to production environment
publicKey := "YOUR_PUBLIC_KEY" // Replace with your public key
secretKey := "YOUR_SECRET_KEY" // Replace with your actual API secret key
apiCreds := aiozstreamsdk.AuthCredentials{
PublicKey: publicKey,
SecretKey: secretKey,
}
client := aiozstreamsdk.ClientBuilder(apiCreds).Build()
// Create a video object
title := "Sample Video Title"
videoData := aiozstreamsdk.CreateMediaRequest{
Title: &title,
}
createResult, err := client.Video.Create(videoData)
if err != nil {
fmt.Fprintf(os.Stderr, "Error creating video: %v\n", err)
return
}
videoId := createResult.Data.Id // Get the video ID from the response
// Open the video file
videoFile, err := os.Open("./path/to/video.mp4")
if err != nil {
fmt.Println("Error opening video file:", err)
return
}
defer videoFile.Close() // Close the file after use
fileInfo, err := videoFile.Stat()
if err != nil {
fmt.Fprintf(os.Stderr, "Error getting file info: %v\n", err)
return
}
fileSize := fileInfo.Size()
fileName := fileInfo.Name()
// Option 1: Use client upload with videoId
err = client.UploadVideo(context.Background(), *videoId, fileName, videoFile, fileSize)
if err != nil {
fmt.Fprintf(os.Stderr, "Error uploading video with client: %v\n", err)
return
}
// Option 2: Upload parts yourself
// This example is commented out as you already used option 1
//_, err = client.Video.UploadPart(*videoId, nil, nil, "./path/to/video.mp4", videoFile, fileInfo.Size())
//if err != nil {
// fmt.Fprintf(os.Stderr, "Error uploading video part: %v\n", err)
// return
//}
//
//success, err := client.Video.UploadVideoComplete(*videoId)
//if err != nil {
// fmt.Fprintf(os.Stderr, "Error completing video upload: %v\n", err)
// return
//}
//
//jsonString, err := json.MarshalIndent(success, "", " ")
//if err != nil {
// fmt.Fprintf(os.Stderr, "Error marshalling response: %v\n", err)
// return
//}
//fmt.Println(string(jsonString))
fmt.Println("Video uploaded successfully!")
}Documentation
API endpoints
All urls are relative to https://api.aiozstream.network/api (opens in a new tab)
API key
Retrieve an instance of the API key:
secretKey := "YOUR_SECRET_KEY" // Replace with your actual secret key
publicKey := "YOUR_PUBLIC_KEY" // Replace with your public key
apiCreds := aiozstreamsdk.AuthCredentials{
PublicKey: publicKey,
SecretKey: secretKey,
}
client := aiozstreamsdk.ClientBuilder(apiCreds).Build()
apiKeyApi := client.ApiKeyEndpoints
| Method | HTTP request | Description |
|---|---|---|
| Create (opens in a new tab) | Post /api_keys | Create API key |
| Update (opens in a new tab) | Patch /api_keys/{id} | Rename API key |
| Delete (opens in a new tab) | Delete /api_keys/{id} | Delete API key |
| List (opens in a new tab) | Get /api_keys | Get list API keys |
Players
Retrieve an instance of the players API:
secretKey := "YOUR_SECRET_KEY" // Replace with your actual secret key
publicKey := "YOUR_PUBLIC_KEY" // Replace with your public key
apiCreds := aiozstreamsdk.AuthCredentials{
PublicKey: publicKey,
SecretKey: secretKey,
}
client := aiozstreamsdk.ClientBuilder(apiCreds).Build()
playersApi := client.PlayersEndpoints
| Method | HTTP request | Description |
|---|---|---|
| Create (opens in a new tab) | Post /players | Create a player theme |
| Get (opens in a new tab) | Get /players/{id} | Get a player theme by ID |
| Update (opens in a new tab) | Patch /players/{id} | Update a player theme by ID |
| Delete (opens in a new tab) | Delete /players/{id} | Delete a player theme by ID |
| List (opens in a new tab) | Get /players | List all player themes |
| UploadLogo (opens in a new tab) | Post /players/{id}/logo | Upload a logo for a player theme by ID |
| DeleteLogo (opens in a new tab) | Delete /players/{id}/logo | Delete a logo for a player theme by ID |
| AddPlayer (opens in a new tab) | Post /players/add-player | Add a player theme to a video |
| RemovePlayer (opens in a new tab) | Post /players/remove-player | Remove a player theme from a video |
Playlist
Retrieve an instance of the playlist API:
secretKey := "YOUR_SECRET_KEY" // Replace with your actual secret key
publicKey := "YOUR_PUBLIC_KEY" // Replace with your public key
apiCreds := aiozstreamsdk.AuthCredentials{
PublicKey: publicKey,
SecretKey: secretKey,
}
client := aiozstreamsdk.ClientBuilder(apiCreds).Build()
playlistApi := client.PlaylistEndpoints
| Method | HTTP request | Description |
|---|---|---|
| AddVideoToPlaylist (opens in a new tab) | Post /playlists/{id}/items | Add a video to a playlist |
| CreatePlaylist (opens in a new tab) | Post /playlists/create | Create a playlist |
| DeletePlaylistById (opens in a new tab) | Delete /playlists/{id} | Delete a playlist by ID |
| DeletePlaylistThumbnail (opens in a new tab) | Delete /playlists/{id}/thumbnail | Delete a playlist thumbnail |
| GetPlaylistById (opens in a new tab) | Get /playlists/{id} | Get playlist by ID |
| GetPlaylistPublicInfo (opens in a new tab) | Get /playlists/{id}/player.json | Get a playlist public |
| GetPlaylists (opens in a new tab) | Post /playlists | Get user's playlists |
| MoveVideoInPlaylist (opens in a new tab) | Put /playlists/{id}/items | Move a video in a playlist |
| RemoveVideoFromPlaylist (opens in a new tab) | Delete /playlists/{id}/items/{item_id} | Remove a video from a playlist |
| UpdatePlaylist (opens in a new tab) | Patch /playlists/{id} | Update a playlist |
Video
Retrieve an instance of the video API:
secretKey := "YOUR_SECRET_KEY" // Replace with your actual secret key
publicKey := "YOUR_PUBLIC_KEY" // Replace with your public key
apiCreds := aiozstreamsdk.AuthCredentials{
PublicKey: publicKey,
SecretKey: secretKey,
}
client := aiozstreamsdk.ClientBuilder(apiCreds).Build()
videoApi := client.VideoEndpoints
| Method | HTTP request | Description |
|---|---|---|
| Create (opens in a new tab) | Post /videos/create | Create video object |
| Update (opens in a new tab) | Patch /videos/{id} | update video info |
| Delete (opens in a new tab) | Delete /videos/{id} | Delete video |
| UploadThumbnail (opens in a new tab) | Post /videos/{id}/thumbnail | Upload video thumbnail |
| DeleteThumbnail (opens in a new tab) | Delete /videos/{id}/thumbnail | Delete video thumbnail |
| CreateCaption (opens in a new tab) | Post /videos/{id}/captions/{lan} | Create a new video caption |
| DeleteCaption (opens in a new tab) | Delete /videos/{id}/captions/{lan} | Delete a video caption |
| GetCaptions (opens in a new tab) | Get /videos/{id}/captions | Get video captions |
| GetCost (opens in a new tab) | Get /videos/cost | get video transcoding cost |
| GetDetail (opens in a new tab) | Get /videos/{id} | get video detail |
| GetVideoList (opens in a new tab) | Post /videos | Get user videos list |
| GetVideoPlayerInfo (opens in a new tab) | Get /videos/{id}/player.json | Get video object |
| SetDefaultCaption (opens in a new tab) | Patch /videos/{id}/captions/{lan} | Set default caption |
| UploadPart (opens in a new tab) | Post /videos/{id}/part | Upload part of video |
| UploadVideoComplete (opens in a new tab) | Get /videos/{id}/complete | Get upload video when complete |
Video chapter
Retrieve an instance of the video chapter API:
secretKey := "YOUR_SECRET_KEY" // Replace with your actual secret key
publicKey := "YOUR_PUBLIC_KEY" // Replace with your public key
apiCreds := aiozstreamsdk.AuthCredentials{
PublicKey: publicKey,
SecretKey: secretKey,
}
client := aiozstreamsdk.ClientBuilder(apiCreds).Build()
videoChapterApi := client.VideoChapterEndpoints
| Method | HTTP request | Description |
|---|---|---|
| Create (opens in a new tab) | Post /videos/{id}/chapters/{lan} | Create a video chapter |
| Get (opens in a new tab) | Get /videos/{id}/chapters | Get video chapters |
| Delete (opens in a new tab) | Delete /videos/{id}/chapters/{lan} | Delete a video chapter |
Webhook
Retrieve an instance of the webhook API:
secretKey := "YOUR_SECRET_KEY" // Replace with your actual secret key
publicKey := "YOUR_PUBLIC_KEY" // Replace with your public key
apiCreds := aiozstreamsdk.AuthCredentials{
PublicKey: publicKey,
SecretKey: secretKey,
}
client := aiozstreamsdk.ClientBuilder(apiCreds).Build()
webhookApi := client.WebhookEndpoints
| Method | HTTP request | Description |
|---|---|---|
| Create (opens in a new tab) | Post /webhooks | Create webhook |
| Get (opens in a new tab) | Get /webhooks/{id} | Get user's webhook by id |
| Update (opens in a new tab) | Patch /webhooks/{id} | Update event webhook |
| Delete (opens in a new tab) | Delete /webhooks/{id} | Delete webhook |
| List (opens in a new tab) | Get /webhooks | Get list webhooks |
| Check (opens in a new tab) | Post /webhooks/check/{id} | Check webhook by id |