The Go SDK has been rewritten for v5 and contains significant changes.
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:
package main import "os" func main() { client := muxgo.NewAPIClient( muxgo.NewConfiguration(muxgo.WithBasicAuth(os.Getenv("MUX_TOKEN_ID"), os.Getenv("MUX_TOKEN_SECRET"))) ) }
New:
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.
package main func main() { d, err := client.DimensionsApi.ListDimensions() }
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:
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:
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
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}, }) }
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.
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)) }
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) }