Go SDK
Learn how the FastPix Go SDK enables video uploads, live streaming, and playback management in Go applications.
Add secure, scalable video to your Go project
The FastPix Go SDK gives you everything you need to manage video from your backend. Upload files from a public URL, attach metadata, and retrieve playback links, all without building encoding pipelines or managing storage. With this SDK, you can:
- Upload and organize video assets
- Define access control and metadata
- Generate HLS playback URLs
- Streamline video delivery from your Go server
Prerequisite
Before you start using the FastPix Golang SDK, make sure you have the following:
- Go 1.20 or later: This SDK is compatible with Go 1.20 or higher
- Go modules enabled: Ensure your project uses Go modules for dependency management
- FastPix API credentials: You’ll need an Access Key and a Secret Key (HTTP Basic Auth). You can generate these credentials by following the steps in the Authentication guide.
- Basic understanding of Go and REST APIs: Familiarity with Go development and API integration concepts
Installation
Install the SDK using go get:
go get github.com/FastPix/fastpix-goImport the SDK
import (
"context"
"github.com/FastPix/fastpix-go"
"github.com/FastPix/fastpix-go/models/components"
)Example
Let's create a file named main.go
This example shows how to upload a video from a public URL with metadata and public access:
NOTE
In the following example, replaceyour-access-token-idandyour-secret-keywith the Access Token ID and Secret Key values from the.envfile you downloaded.
package main
import (
"bytes"
"context"
"encoding/json"
"fmt"
"io"
"log"
"github.com/FastPix/fastpix-go/models/components"
fastpixgo "github.com/FastPix/fastpix-go"
)
func main() {
ctx := context.Background()
s := fastpixgo.New(
fastpixgo.WithSecurity(components.Security{
Username: fastpixgo.Pointer("your-access-token"),
Password: fastpixgo.Pointer("your-secret-key"),
}),
)
res, err := s.InputVideo.Create(ctx, components.CreateMediaRequest{
Inputs: []components.Input{
components.CreateInputPullVideoInput(
components.PullVideoInput{},
),
},
Metadata: map[string]string{
"your-metadata-key": "your-metadata-value",
},
})
if err != nil {
log.Fatal(err)
}
if res.CreateMediaSuccessResponse != nil {
// Read raw response body to preserve API's JSON field order
if res.HTTPMeta.Response != nil && res.HTTPMeta.Response.Body != nil {
rawBody, err := io.ReadAll(res.HTTPMeta.Response.Body)
if err == nil && len(rawBody) > 0 {
var buf bytes.Buffer
if err := json.Indent(&buf, rawBody, "", " "); err == nil {
fmt.Println(buf.String())
} else {
fmt.Println(string(rawBody))
}
} else {
responseJSON, err := json.MarshalIndent(res.CreateMediaSuccessResponse, "", " ")
if err != nil {
log.Printf("Error marshaling response: %v", err)
fmt.Printf("Response: %+v\n", res.CreateMediaSuccessResponse)
} else {
fmt.Println(string(responseJSON))
}
}
} else {
responseJSON, err := json.MarshalIndent(res.CreateMediaSuccessResponse, "", " ")
if err != nil {
log.Printf("Error marshaling response: %v", err)
fmt.Printf("Response: %+v\n", res.CreateMediaSuccessResponse)
} else {
fmt.Println(string(responseJSON))
}
}
} else if res.DefaultError != nil {
fmt.Printf("Error: %+v\n", res.DefaultError)
}
}After the video is processed, you can use the media ID to fetch playback info, monitor status, or transform content via API.
Run the example
To execute the Go script, use the following command. Make sure to replace main.go with your actual file name if it's different:
go run main.goNOTE
Some methods might throw errors when you are on a trial plan.
Full documentation
See the FastPix Go SDK for additional examples, API methods, and advanced usage.
Updated 15 days ago