Git Product home page Git Product logo

mux-go's Introduction

Mux Go Banner

GoDoc

Mux Go

Official Mux API wrapper for golang projects, supporting both Mux Data and Mux Video.

Mux Video is an API-first platform, powered by data and designed by video experts to make beautiful video possible for every development team.

Mux Data is a platform for monitoring your video streaming performance with just a few lines of code. Get in-depth quality of service analytics on web, mobile, and OTT devices.

Not familiar with Mux? Check out https://mux.com/ for more information.

Installation

go get github.com/muxinc/mux-go/v5

Getting Started

Overview

Mux Go is a code generated lightweight wrapper around the Mux REST API and reflects them accurately. This has a few consequences you should watch out for:

  1. For almost all API responses, the object you're looking for will be in the data field on the API response object, as in the example below. This is because we designed our APIs with similar concepts to the JSON:API standard. This means we'll be able to return more metadata from our API calls (such as related entities) without the need to make breaking changes to our APIs. We've decided not to hide that in this library.

  2. We don't use a lot of object orientation. For example API calls that happen on a single asset don't exist in the asset class, but are API calls in the AssetsApi which require an asset ID.

Authentication

To use the Mux API, you'll need an access token and a secret. Details on obtaining these can be found here in the Mux documentation.

Its up to you to manage your token and secret. In our examples, we read them from MUX_TOKEN_ID and MUX_TOKEN_SECRET in your environment.

Example Usage

Below is a quick example of using mux-go to list the Video assets stored in your Mux account.

Be sure to also checkout the exmples directory.

package main

import (
	"fmt"
	"os"

	"github.com/muxinc/mux-go/v5"
)

func main() {
	// API Client Init
	client := muxgo.NewAPIClient(
		muxgo.NewConfiguration(
			muxgo.WithBasicAuth(os.Getenv("MUX_TOKEN_ID"), os.Getenv("MUX_TOKEN_SECRET")),
		))

	// List Assets
	fmt.Println("Listing Assets...\n")
	r, err := client.AssetsApi.ListAssets()
	if err != nil {
		fmt.Printf("err: %s \n\n", err)
		os.Exit(255)
	}
	for _, asset := range r.Data {
		fmt.Printf("Asset ID: %s\n", asset.Id)
		fmt.Printf("Status: %s\n", asset.Status)
		fmt.Printf("Duration: %f\n\n", asset.Duration)
	}
}

Errors & Error Handling

All API calls return an err as their final return value. Below is documented the errors you might want to check for. You can check error.Body on all errors to see the full HTTP response.

BadRequestError

BadRequestError is returned when a you make a bad request to Mux, this likely means you've passed in an invalid parameter to the API call.

UnauthorizedError

UnauthorizedError is returned when Mux cannot authenticate your request. You should check you have configured your credentials correctly.

ForbiddenError

ForbiddenError is returned you don't have permission to access that resource. You should check you have configured your credentials correctly.

NotFoundError

NotFoundError is returned when a resource is not found. This is useful when trying to get an entity by its ID.

TooManyRequestsError

TooManyRequestsError is returned when you exceed the maximum number of requests allowed for a given time period. Please get in touch with [email protected] if you need to talk about this limit.

ServiceError

ServiceError is returned when Mux returns a HTTP 5XX Status Code. If you encounter this reproducibly, please get in touch with [email protected].

GenericOpenAPIError

GenericOpenAPIError is a fallback Error which may be returned in some edge cases. This will be deprecated in a later release but remains present for API compatibility.

Documentation

Be sure to check out the documentation in the docs directory.

Issues

If you run into problems, please raise a GitHub issue, filling in the issue template. We'll take a look as soon as possible.

Contributing

Please do not submit PRs against this package. It is generated from our OpenAPI definitions - Please open an issue instead!

License

MIT License. Copyright 2019 Mux, Inc.

mux-go's People

Contributors

alexdechaves avatar brendanjryan avatar eropple avatar jaredsmith avatar joncalhoun avatar jsanford8 avatar philcluff avatar therealwardo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mux-go's Issues

Missing "connected" property on LiveStream

Though no mention is made in the API docs, a property which has been very helpful to me is connected on LiveStream as typically found in webhook data.

This property is very helpful in driving UI indicators for when a stream goes live.

This property is currently missing on the LiveStream model.

For example:

{
  "stream_key": "******",
  "status": "active",
  "recording": true,
  "playback_ids": [
    {
      "policy": "public",
      "id": "ljCTZK94b7ADmwCFR00KyLMda11jx21sTEKBJIxYIpBs"
    }
  ],
  "passthrough": "GHC9jb6DOsbHZs4NAifM",
  "new_asset_settings": {
    "playback_policies": [
      "public"
    ]
  },
  "low_latency": true,
  "latency_mode": "low",
  "id": "joIgTGuMkyk00006jIsWVmukX007PTDOnB01uqiYUlqUUfA",
  "created_at": 1644527397,
  "connected": true,
  "active_asset_id": "OX5xoQAo2NBqZdFzQr8MpZ532vN01wHXfMO2bXMvagY00"
}

Bad module path in v1.0.0

Looks like someone forgot to specify the --git-user-id and --git-repo-id flags when running openapi-generator-cli @eropple?

go get: github.com/muxinc/[email protected] updating to
        github.com/muxinc/[email protected]: parsing go.mod:
        module declares its path as: github.com/GIT_USER_ID/GIT_REPO_ID
                but was required as: github.com/muxinc/mux-go

Allow custom http.Transport or http.Client

I'd like to add tracing to mux http calls but need a way to tap into the http.Client that mux uses under the hood. Typically other libraries expose a way to modify the http.Transport of the http.Client they're using.

I'm thinking maybe exposing this via the ConfigurationOption func:

func WithHTTPRoundTripper(roundTripper http.RoundTripper) ConfigurationOption {
	return func(c *Configuration) {
		c.httpRoundTripper = roundTripper
	}
}

and later on in client.go

if cfg.httpRoundTripper == nil {
    cfg.httpRoundTripper = http.DefaultTransport
}

c.httpc = &http.Client{
    Timeout: cfg.timeout,
    Transport: cfg.httpRoundTripper
}

json.Marshal on muxgo.PlaybackRestriction errors out, v3.2.0

When using the muxClient.PlaybackRestrictionsApi.ListPlaybackRestrictions() method, I'm trying to json.Marshal the response into a []muxgo.PlaybackRestriction struct and get an err back:

json: cannot unmarshal object into Go value of type []muxgo.PlaybackRestriction

I believe in the api_playback_restrictions.go, specifically the ListPlaybackRestrictions method, it returns back a slice of []PlaybackRestriction, which the PlaybackRestriction type does not include the Data field.

So anytime I try to list all my playbacks and json.Marshal them, they error out because the Data Field is missing. Here' an example json response from your api.

{
  "data": [
    {
      "updated_at": "1643990876",
      "referrer": {
        "allowed_domains": [
          "example.com",
          "hello.com"
        ]
      },
      "id": "xxxxxxxx",
      "created_at": "1643990876"
    },
    {
      "updated_at": "1643990866",
      "referrer": {
        "allowed_domains": [
          "example2.com",
          "hello2.com"
        ]
      },
      "id": "xxxxxx",
      "created_at": "1643990866"
    }

Also, the same issues are happening for the Create and Get actions on the PlaybackRestriction API. No Data Field on the PlaybackRestriction struct.

Typed models for working with webhooks

Not a huge deal but it would be nice if this package included typed models for easier webhook processing.

For example, I'd like to process the payload data in a video.live_stream.created webhook event however there are incompatible differences with the near-identical muxgo.LiveStream struct.

var payload struct {
    Type string           `json:"type"`
    Data muxgo.LiveStream `json:"data"`
}
if err := resty.Unmarshalc(resty.New(), "application/json", body, &payload); err != nil {
    panic("json: cannot unmarshal number into Go struct field LiveStream.data.created_at of type string")
}

In this particular case, the webhook uses integer dates whereas the API model uses RFC3339 dates.

V3.2.0 resolves to V1.1.0. Update go.mod file.

I noticed an issue when getting the latest muxgo sdk, v3.2.0. I first tried to use the PlaybackRestrictionsApiService in the go sdk to create a playback restriction, but wasn't able to. It resolves to version v1.1.0 and not the latest version.

go get github.com/muxinc/mux-go 

I believe the reason is because of the semantic versioning for go module versions.

I think a simple fix would be just adding this line of code to the go.mod file:

So this line of code would be:

module github.com/muxinc/mux-go/v3

Or am I doing something incorrectly here?

Here are a few references and examples from other 3rd party SDKs (packages)

Unmarshal errors with multiple exercise functions

Hey guys, I just tried your metrics example code and three out of five examples don't work. I'm running on go1.14.4 darwin/amd64 with mux-go v0.8.0.

Input:

bdvopts := muxgo.ListBreakdownValuesParams{GroupBy: "browser", Timeframe: []string{"7:days"}}
bdv, err := client.MetricsApi.ListBreakdownValues("video_startup_time", muxgo.WithParams(&bdvopts))

Error:

err: json: cannot unmarshal string into Go struct field BreakdownValue.data.negative_impact of type int32

exit status 255

Input:

ovopts := muxgo.GetOverallValuesParams{Timeframe: []string{"7:days"}}
ov, err := client.MetricsApi.GetOverallValues("video_startup_time", muxgo.WithParams(&ovopts))

Error:

err: json: cannot unmarshal string into Go struct field OverallValues.data.total_views of type int64

exit status 255

Input:

iopts := muxgo.ListInsightsParams{Timeframe: []string{"7:days"}}
is, err := client.MetricsApi.ListInsights("video_startup_time", muxgo.WithParams(&iopts))

Error:

err: json: cannot unmarshal string into Go struct field Insight.data.total_views of type int64

exit status 255

The list-filter-values exercise also doesn't work:

Input:

fp := muxgo.ListFilterValuesParams{Timeframe: []string{"7:days"}}
fv, err := client.FiltersApi.ListFilterValues("browser", muxgo.WithParams(&fp))

Error:

err: json: cannot unmarshal string into Go struct field FilterValue.data.total_count of type int64

exit status 255

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.