Upgrade to Mux v5

Go pattern

The Go SDK has been rewritten for v5 and contains significant changes.


Apply with the Grit CLI
grit apply mux_go_v5

Client initialization

The client initialization method has renamed to NewClient and configuration is now set using muxoption calls instead of NewConfiguration.

Basic Auth has been replaced with WithTokenID and WithTokenSecret options.

Old:

BEFORE
package main

import "os"

func main() {
  client := muxgo.NewAPIClient(
    muxgo.NewConfiguration(muxgo.WithBasicAuth(os.Getenv("MUX_TOKEN_ID"), os.Getenv("MUX_TOKEN_SECRET")))
  )
}

New:

AFTER
package main

import "os"
import "github.com/muxinc/mux-go/muxoption"

func main() {
  client := mux.NewClient(muxoption.WithTokenID(os.Getenv("MUX_TOKEN_ID")), muxoption.WithTokenSecret(os.Getenv("MUX_TOKEN_SECRET")))
}

Context is now required

All API calls now require a context to be passed in. This is to allow for better control over the request lifecycle.

BEFORE
package main

func main() {
	d, err := client.DimensionsApi.ListDimensions()
}
AFTER
package main
import "context"

func main() {
	d, err := client.Data.Dimensions.List(context.TODO())
}

Request parameters

All request parameters are now wrapped in a generic Field type, which helps to distinguish zero values from null or omitted fields. In most cases, primitive values should simply be wrapped in muxgo.F().

Fields which you want to be null must now be sent and should be specified using muxgo.Null[<type>]().

Before:

BEFORE
package main

import muxgo "github.com/muxinc/mux-go"

func main() {
	req := muxgo.CreateAssetRequest{Url: "https://storage.googleapis.com/muxdemofiles/mux-video-intro.mp4", PlaybackPolicy: "public",}
}

After:

AFTER
package main

import muxgo "github.com/muxinc/mux-go"
import "github.com/muxinc/mux-go/video"

func main() {
	req := video.AssetNewParams{Url: muxgo.F("https://storage.googleapis.com/muxdemofiles/mux-video-intro.mp4"), PlaybackPolicy: muxgo.F("public")}
}

Video API

The Video API has been moved under the Video namespace of the client and methods have been renamed:

  • AssetsApi.CreateAsset -> Video.Assets.New
BEFORE
package main

import muxgo "github.com/muxinc/mux-go"

func main() {
	asset, err := client.AssetsApi.CreateAsset(muxgo.CreateAssetRequest{Input: []muxgo.InputSettings{{
			Url: "https://storage.googleapis.com/muxdemofiles/mux-video-intro.mp4",
		}},
		PlaybackPolicy: []muxgo.PlaybackPolicy{muxgo.PUBLIC},
	})
}
AFTER
package main

import muxgo "github.com/muxinc/mux-go"
import "context"
import "github.com/muxinc/mux-go/video"

func main() {
	asset, err := client.Video.Assets.New(context.TODO(), video.AssetNewParams{Input: muxgo.F([]video.AssetNewParamsInput{{
			Url: muxgo.F("https://storage.googleapis.com/muxdemofiles/mux-video-intro.mp4"),
		}}),
		PlaybackPolicy: muxgo.F([]muxgo.PlaybackPolicy{muxgo.PUBLIC})})
}

Dimensions API

The Dimensions API has been moved under the Data namespace of the client, with two methods: List and ListValues. The ListValues method receives params from the data.DimensionListValuesParams struct.

BEFORE
package main

import muxgo "github.com/muxinc/mux-go"

func main() {
	d, err := client.DimensionsApi.ListDimensions()

	ldp := muxgo.ListDimensionValuesParams{Timeframe: []string{"7:days"}}
	dv, err := client.DimensionsApi.ListDimensionValues("browser", muxgo.WithParams(&ldp))
}
AFTER
package main

import muxgo "github.com/muxinc/mux-go"
import "github.com/muxinc/mux-go/data"
import "context"

func main() {
	d, err := client.Data.Dimensions.List(context.TODO())

	ldp := data.DimensionListValuesParams{Timeframe: muxgo.F([]string{muxgo.F("7:days")})}
	dv, err := client.Data.Dimensions.ListValues(context.TODO(), "browser", &ldp)
}