Skip to content

Go SDK simplifies integration with the FastPix platform. This SDK is designed for secure and efficient communication with the FastPix API.

License

Notifications You must be signed in to change notification settings

FastPix/fastpix-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FastPix Go SDK

A robust, type-safe Go SDK designed for seamless integration with the FastPix API platform.

Introduction

The FastPix Go SDK simplifies integration with the FastPix platform. It provides a clean, Go interface for secure and efficient communication with the FastPix API, enabling easy management of media uploads, live streaming, on‑demand content, playlists, video analytics, and signing keys for secure access and token management. It is intended for use with Go 1.22 and above.

Prerequisites

Environment and Version Support

Requirement Version Description
Go 1.22+ Core runtime environment
Go Modules Enabled Dependency management for Go packages
Internet Required API communication and authentication

Pro Tip: We recommend using Go 1.23+ for optimal performance and the latest language features.

Getting Started with FastPix

To get started with the FastPix Go SDK, ensure you have the following:

  • The FastPix APIs are authenticated using a Username and a Password. You must generate these credentials to use the SDK.

  • Follow the steps in the Authentication with Basic Auth guide to obtain your credentials.

Environment Variables (Optional)

Configure your FastPix credentials using environment variables for enhanced security and convenience:

# Set your FastPix credentials
export FASTPIX_USERNAME="your-access-token"
export FASTPIX_PASSWORD="your-secret-key"

Security Note: Never commit your credentials to version control. Use environment variables or secure credential management systems.

Table of Contents

Setup

Installation

Install the FastPix Go SDK using Go modules:

go get github.com/FastPix/fastpix-go

Imports

Import the necessary modules for your FastPix integration:

// Basic imports
import (
    "context"
    "github.com/FastPix/fastpix-go"
    "github.com/FastPix/fastpix-go/models/components"
)

Initialization

Initialize the FastPix SDK with your credentials:

import (
    "context"
    "github.com/FastPix/fastpix-go"
    "github.com/FastPix/fastpix-go/models/components"
)

client := fastpix.New(
    fastpix.WithSecurity(components.Security{
        Username: fastpix.Pointer("your-access-token"),
        Password: fastpix.Pointer("your-secret-key"),
    }),
)

Or using environment variables:

import (
    "context"
    "os"
    "github.com/FastPix/fastpix-go"
    "github.com/FastPix/fastpix-go/models/components"
)

client := fastpix.New(
    fastpix.WithSecurity(components.Security{
        Username: fastpix.Pointer(os.Getenv("FASTPIX_USERNAME")),
        Password: fastpix.Pointer(os.Getenv("FASTPIX_PASSWORD")),
    }),
)

Example Usage

Example

package main

import (
	"context"
	fastpix "github.com/FastPix/fastpix-go"
	"github.com/FastPix/fastpix-go/models/components"
	"log"
)

func main() {
	ctx := context.Background()

	s := fastpix.New(
		fastpix.WithSecurity(components.Security{
			Username: fastpix.Pointer("your-access-token"),
			Password: fastpix.Pointer("your-secret-key"),
		}),
	)

	res, err := s.InputVideo.CreateMedia(ctx, components.CreateMediaRequest{
		Inputs: []components.Input{
			components.CreateInputVideoInput(
				components.VideoInput{
					Type: "video",
					URL:  "https://static.fastpix.io/sample.mp4",
				},
			),
		},
		Metadata: map[string]string{
			"key1": "value1",
		},
		AccessPolicy: components.CreateMediaRequestAccessPolicyPublic,
	})
	if err != nil {
		log.Fatal(err)
	}
	if res.CreateMediaSuccessResponse != nil {
		// handle response
	}
}

Available Resources and Operations

Comprehensive Go SDK for FastPix platform integration with full API coverage.

Media API

Upload, manage, and transform video content with comprehensive media management capabilities.

For detailed documentation, see FastPix Video on Demand Overview.

Input Video

Manage Videos

Playback

Playlist

Signing Keys

DRM Configurations

Live API

Stream, manage, and transform live video content with real-time broadcasting capabilities.

For detailed documentation, see FastPix Live Stream Overview.

Start Live Stream

Manage Live Stream

Live Playback

Simulcast Stream

Video Data API

Monitor video performance and quality with comprehensive analytics and real-time metrics.

For detailed documentation, see FastPix Video Data Overview.

Metrics

Views

Dimensions

In-Video AI Features

Enhance video content with AI-powered features including moderation, summarization, and intelligent categorization.

For detailed documentation, see Video Moderation Guide.

Error Handling

Handle and manage errors with comprehensive error handling capabilities and detailed error information for all API operations.

  • List Errors - Retrieve comprehensive error logs and diagnostics

Retries

Some of the endpoints in this SDK support retries. If you use the SDK without any configuration, it will fall back to the default retry strategy provided by the API. However, the default retry strategy can be overridden on a per-operation basis, or across the entire SDK.

To change the default retry strategy for a single API call, simply provide a retry.Config object to the call by using the WithRetries option:

package main

import (
	"context"
	fastpix "github.com/FastPix/fastpix-go"
	"github.com/FastPix/fastpix-go/models/components"
	"github.com/FastPix/fastpix-go/retry"
	"log"
	"models/operations"
)

func main() {
	ctx := context.Background()

	s := fastpix.New(
		fastpix.WithSecurity(components.Security{
			Username: fastpix.Pointer("your-access-token"),
			Password: fastpix.Pointer("your-secret-key"),
		}),
	)

	res, err := s.InputVideo.CreateMedia(ctx, components.CreateMediaRequest{
		Inputs: []components.Input{
			components.CreateInputVideoInput(
				components.VideoInput{
					Type: "video",
					URL:  "https://static.fastpix.io/sample.mp4",
				},
			),
		},
		Metadata: map[string]string{
			"key1": "value1",
		},
		AccessPolicy: components.CreateMediaRequestAccessPolicyPublic,
	}, operations.WithRetries(
		retry.Config{
			Strategy: "backoff",
			Backoff: &retry.BackoffStrategy{
				InitialInterval: 1,
				MaxInterval:     50,
				Exponent:        1.1,
				MaxElapsedTime:  100,
			},
			RetryConnectionErrors: false,
		}))
	if err != nil {
		log.Fatal(err)
	}
	if res.CreateMediaSuccessResponse != nil {
		// handle response
	}
}

If you'd like to override the default retry strategy for all operations that support retries, you can use the WithRetryConfig option at SDK initialization:

package main

import (
	"context"
	fastpix "github.com/FastPix/fastpix-go"
	"github.com/FastPix/fastpix-go/models/components"
	"github.com/FastPix/fastpix-go/retry"
	"log"
)

func main() {
	ctx := context.Background()

	s := fastpix.New(
		fastpix.WithRetryConfig(
			retry.Config{
				Strategy: "backoff",
				Backoff: &retry.BackoffStrategy{
					InitialInterval: 1,
					MaxInterval:     50,
					Exponent:        1.1,
					MaxElapsedTime:  100,
				},
				RetryConnectionErrors: false,
			}),
		fastpix.WithSecurity(components.Security{
			Username: fastpix.Pointer("your-access-token"),
			Password: fastpix.Pointer("your-secret-key"),
		}),
	)

	res, err := s.InputVideo.CreateMedia(ctx, components.CreateMediaRequest{
		Inputs: []components.Input{
			components.CreateInputVideoInput(
				components.VideoInput{
					Type: "video",
					URL:  "https://static.fastpix.io/sample.mp4",
				},
			),
		},
		Metadata: map[string]string{
			"key1": "value1",
		},
		AccessPolicy: components.CreateMediaRequestAccessPolicyPublic,
	})
	if err != nil {
		log.Fatal(err)
	}
	if res.CreateMediaSuccessResponse != nil {
		// handle response
	}
}

Error Handling

Handling errors in this SDK should largely match your expectations. All operations return a response object or an error, they will never return both.

By Default, an API error will return apierrors.APIError. When custom error responses are specified for an operation, the SDK may also return their associated error. You can refer to respective Errors tables in SDK docs for more details on possible error types for each operation.

For example, the CreateMedia function may return the following errors:

Error Type Status Code Content Type
apierrors.BadRequestError 400 application/json
apierrors.InvalidPermissionError 401 application/json
apierrors.ForbiddenError 403 application/json
apierrors.ValidationErrorResponse 422 application/json
apierrors.APIError 4XX, 5XX */*

Example

package main

import (
	"context"
	"errors"
	fastpix "github.com/FastPix/fastpix-go"
	"github.com/FastPix/fastpix-go/models/apierrors"
	"github.com/FastPix/fastpix-go/models/components"
	"log"
)

func main() {
	ctx := context.Background()

	s := fastpix.New(
		fastpix.WithSecurity(components.Security{
			Username: fastpix.Pointer("your-access-token"),
			Password: fastpix.Pointer("your-secret-key"),
		}),
	)

	res, err := s.InputVideo.CreateMedia(ctx, components.CreateMediaRequest{
		Inputs: []components.Input{
			components.CreateInputVideoInput(
				components.VideoInput{
					Type: "video",
					URL:  "https://static.fastpix.io/sample.mp4",
				},
			),
		},
		Metadata: map[string]string{
			"key1": "value1",
		},
		AccessPolicy: components.CreateMediaRequestAccessPolicyPublic,
	})
	if err != nil {

		var e *apierrors.BadRequestError
		if errors.As(err, &e) {
			// handle error
			log.Fatal(e.Error())
		}

		var e *apierrors.InvalidPermissionError
		if errors.As(err, &e) {
			// handle error
			log.Fatal(e.Error())
		}

		var e *apierrors.ForbiddenError
		if errors.As(err, &e) {
			// handle error
			log.Fatal(e.Error())
		}

		var e *apierrors.ValidationErrorResponse
		if errors.As(err, &e) {
			// handle error
			log.Fatal(e.Error())
		}

		var e *apierrors.APIError
		if errors.As(err, &e) {
			// handle error
			log.Fatal(e.Error())
		}
	}
}

Server Selection

Override Server URL Per-Client

The default server can be overridden globally using the WithServerURL(serverURL string) option when initializing the SDK client instance. For example:

package main

import (
	"context"
	fastpix "github.com/FastPix/fastpix-go"
	"github.com/FastPix/fastpix-go/models/components"
	"log"
)

func main() {
	ctx := context.Background()

	s := fastpix.New(
		fastpix.WithServerURL("https://api.fastpix.io/v1/"),
		fastpix.WithSecurity(components.Security{
			Username: fastpix.Pointer("your-access-token"),
			Password: fastpix.Pointer("your-secret-key"),
		}),
	)

	res, err := s.InputVideo.CreateMedia(ctx, components.CreateMediaRequest{
		Inputs: []components.Input{
			components.CreateInputVideoInput(
				components.VideoInput{
					Type: "video",
					URL:  "https://static.fastpix.io/sample.mp4",
				},
			),
		},
		Metadata: map[string]string{
			"key1": "value1",
		},
		AccessPolicy: components.CreateMediaRequestAccessPolicyPublic,
	})
	if err != nil {
		log.Fatal(err)
	}
	if res.CreateMediaSuccessResponse != nil {
		// handle response
	}
}

Custom HTTP Client

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/FastPix/fastpix-go"
)

var (
	httpClient = &http.Client{Timeout: 30 * time.Second}
	sdkClient  = fastpix.New(fastpix.WithClient(httpClient))
)

This can be a convenient way to configure timeouts, cookies, proxies, custom headers, and other low-level configuration.

Development

This Go SDK is programmatically generated from our API specifications. Any manual modifications to internal files will be overwritten during subsequent generation cycles.

We value community contributions and feedback. Feel free to submit pull requests or open issues with your suggestions, and we'll do our best to include them in future releases.

Detailed Usage

For comprehensive understanding of each API's functionality, including detailed request and response specifications, parameter descriptions, and additional examples, please refer to the FastPix API Reference.

The API reference offers complete documentation for all available endpoints and features, enabling developers to integrate and leverage FastPix APIs effectively.

<style> :root { --badge-gray-bg: #f3f4f6; --badge-gray-border: #d1d5db; --badge-gray-text: #374151; --badge-blue-bg: #eff6ff; --badge-blue-border: #3b82f6; --badge-blue-text: #3b82f6; } @media (prefers-color-scheme: dark) { :root { --badge-gray-bg: #374151; --badge-gray-border: #4b5563; --badge-gray-text: #f3f4f6; --badge-blue-bg: #1e3a8a; --badge-blue-border: #3b82f6; --badge-blue-text: #93c5fd; } } h1 { border-bottom: none !important; margin-bottom: 4px; margin-top: 0; letter-spacing: 0.5px; font-weight: 600; } .badge-text { letter-spacing: 1px; font-weight: 300; } .badge-container { display: inline-flex; align-items: center; background: var(--badge-gray-bg); border: 1px solid var(--badge-gray-border); border-radius: 6px; overflow: hidden; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif; font-size: 11px; text-decoration: none; vertical-align: middle; } .badge-container.blue { background: var(--badge-blue-bg); border-color: var(--badge-blue-border); } .badge-icon-section { padding: 4px 8px; border-right: 1px solid var(--badge-gray-border); display: flex; align-items: center; } .badge-text-section { padding: 4px 10px; color: var(--badge-gray-text); font-weight: 400; } .badge-container.blue .badge-text-section { color: var(--badge-blue-text); } .badge-link { text-decoration: none; margin-left: 8px; display: inline-flex; vertical-align: middle; } .badge-link:hover { text-decoration: none; } .badge-link:first-child { margin-left: 0; } .badge-icon-section svg { color: var(--badge-gray-text); } .badge-container.blue .badge-icon-section svg { color: var(--badge-blue-text); } </style>

About

Go SDK simplifies integration with the FastPix platform. This SDK is designed for secure and efficient communication with the FastPix API.

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •