W3Stream Go client
W3Stream 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.
Project description
W3Stream's Go client streamlines the coding process. Chunking files is handled for you, as is pagination and refreshing your tokens.
Getting started
Installation
go get github.com/AIOZNetwork/w3stream-go-client
Code sample
For a more advanced usage you can checkout the rest of the documentation in the docs directory
import (
"context"
"fmt"
"os"
w3streamsdk "github.com/AIOZNetwork/w3stream-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 := w3streamsdk.AuthCredentials{
PublicKey: publicKey,
SecretKey: secretKey,
}
client := w3streamsdk.ClientBuilder(apiCreds).Build()
// Create a video object
title := "Sample Video Title"
videoData := w3streamsdk.CreateVideoRequest{
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.w3stream.xyz/api
ApiKey
Retrieve an instance of the ApiKey API:
secretKey := "YOUR_SECRET_KEY" // Replace with your actual secret key
publicKey := "YOUR_PUBLIC_KEY" // Replace with your public key
apiCreds := w3streamsdk.AuthCredentials{
PublicKey: publicKey,
SecretKey: secretKey,
}
client := w3streamsdk.ClientBuilder(apiCreds).Build()
apiKeyApi := client.ApiKey
Endpoints
Method | HTTP request | Description |
---|
Create | Post /api_keys | Create API key |
Update | Patch /api_keys/{id} | Rename api key |
Delete | Delete /api_keys/{id} | Delete API key |
List | Get /api_keys | Get list API keys |
LiveStream
Retrieve an instance of the LiveStream API:
secretKey := "YOUR_SECRET_KEY" // Replace with your actual secret key
publicKey := "YOUR_PUBLIC_KEY" // Replace with your public key
apiCreds := w3streamsdk.AuthCredentials{
PublicKey: publicKey,
SecretKey: secretKey,
}
client := w3streamsdk.ClientBuilder(apiCreds).Build()
liveStreamApi := client.LiveStream
Endpoints
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 := w3streamsdk.AuthCredentials{
PublicKey: publicKey,
SecretKey: secretKey,
}
client := w3streamsdk.ClientBuilder(apiCreds).Build()
playersApi := client.Players
Endpoints
Method | HTTP request | Description |
---|
Create | Post /players | Create a player theme |
Get | Get /players/{id} | Get a player theme by ID |
Update | Patch /players/{id} | Update a player theme by ID |
Delete | Delete /players/{id} | Delete a player theme by ID |
List | Get /players | List all player themes |
UploadLogo | Post /players/{id}/logo | Upload a logo for a player theme by ID |
DeleteLogo | Delete /players/{id}/logo | Delete a logo for a player theme by ID |
AddPlayer | Post /players/add-player | Add a player theme to a video |
RemovePlayer | 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 := w3streamsdk.AuthCredentials{
PublicKey: publicKey,
SecretKey: secretKey,
}
client := w3streamsdk.ClientBuilder(apiCreds).Build()
playlistApi := client.Playlist
Endpoints
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 := w3streamsdk.AuthCredentials{
PublicKey: publicKey,
SecretKey: secretKey,
}
client := w3streamsdk.ClientBuilder(apiCreds).Build()
videoApi := client.Video
Endpoints
VideoChapter
Retrieve an instance of the VideoChapter API:
secretKey := "YOUR_SECRET_KEY" // Replace with your actual secret key
publicKey := "YOUR_PUBLIC_KEY" // Replace with your public key
apiCreds := w3streamsdk.AuthCredentials{
PublicKey: publicKey,
SecretKey: secretKey,
}
client := w3streamsdk.ClientBuilder(apiCreds).Build()
videoChapterApi := client.VideoChapter
Endpoints
Method | HTTP request | Description |
---|
Create | Post /videos/{id}/chapters/{lan} | Create a video chapter |
Get | Get /videos/{id}/chapters | Get video chapters |
Delete | 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 := w3streamsdk.AuthCredentials{
PublicKey: publicKey,
SecretKey: secretKey,
}
client := w3streamsdk.ClientBuilder(apiCreds).Build()
webhookApi := client.Webhook
Endpoints
Method | HTTP request | Description |
---|
Create | Post /webhooks | Create webhook |
Get | Get /webhooks/{id} | Get user's webhook by id |
Update | Patch /webhooks/{id} | Update event webhook |
Delete | Delete /webhooks/{id} | Delete webhook |
List | Get /webhooks | Get list webhooks |
Check | Post /webhooks/check/{id} | Check webhook by id |
Models
Have you gotten use from this API client?
Please take a moment to leave a star on the client ⭐
This helps other users to find the clients and also helps us understand which clients are most popular. Thank you!