github.com/muxinc/mux-go@v1.1.1/README.md (about) 1  2 3  4 [](https://godoc.org/github.com/muxinc/mux-go) 5 6 # Mux Go 7 8 Official Mux API wrapper for golang projects, supporting both Mux Data and Mux Video. 9 10 [Mux Video](https://mux.com/video) is an API-first platform, powered by data and designed by video experts to make beautiful video possible for every development team. 11 12 [Mux Data](https://mux.com/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. 13 14 Not familiar with Mux? Check out https://mux.com/ for more information. 15 16 ## Installation 17 18 ``` 19 go get github.com/muxinc/mux-go 20 ``` 21 22 ## Getting Started 23 24 ### Overview 25 26 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: 27 28 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](https://jsonapi.org/) 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. 29 30 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. 31 32 ### Authentication 33 34 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.](https://docs.mux.com/docs#section-1-get-an-api-access-token) 35 36 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. 37 38 ### Example Usage 39 40 Below is a quick example of using mux-go to list the Video assets stored in your Mux account. 41 42 Be sure to also checkout the [exmples directory](examples/). 43 44 ```go 45 package main 46 47 import ( 48 "fmt" 49 "os" 50 51 "github.com/muxinc/mux-go" 52 ) 53 54 func main() { 55 // API Client Init 56 client := muxgo.NewAPIClient( 57 muxgo.NewConfiguration( 58 muxgo.WithBasicAuth(os.Getenv("MUX_TOKEN_ID"), os.Getenv("MUX_TOKEN_SECRET")), 59 )) 60 61 // List Assets 62 fmt.Println("Listing Assets...\n") 63 r, err := client.AssetsApi.ListAssets() 64 if err != nil { 65 fmt.Printf("err: %s \n\n", err) 66 os.Exit(255) 67 } 68 for _, asset := range r.Data { 69 fmt.Printf("Asset ID: %s\n", asset.Id) 70 fmt.Printf("Status: %s\n", asset.Status) 71 fmt.Printf("Duration: %f\n\n", asset.Duration) 72 } 73 } 74 ``` 75 76 ## Errors & Error Handling 77 78 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. 79 80 ### BadRequestError 81 82 `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. 83 84 ### UnauthorizedError 85 86 `UnauthorizedError` is returned when Mux cannot authenticate your request. [You should check you have configured your credentials correctly.](#authentication) 87 88 ### ForbiddenError 89 90 `ForbiddenError` is returned you don't have permission to access that resource. [You should check you have configured your credentials correctly.](#authentication) 91 92 ### NotFoundError 93 94 `NotFoundError` is returned when a resource is not found. This is useful when trying to get an entity by its ID. 95 96 ### TooManyRequestsError 97 98 `TooManyRequestsError` is returned when you exceed the maximum number of requests allowed for a given time period. Please get in touch with [support@mux.com](mailto:support@mux.com) if you need to talk about this limit. 99 100 ### ServiceError 101 102 `ServiceError` is returned when Mux returns a HTTP 5XX Status Code. If you encounter this reproducibly, please get in touch with [support@mux.com](mailto:support@mux.com). 103 104 ### GenericOpenAPIError 105 106 `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. 107 108 ## Documentation 109 110 [Be sure to check out the documentation in the `docs` directory.](docs/) 111 112 ## Issues 113 114 If you run into problems, [please raise a GitHub issue,](https://github.com/muxinc/mux-go/issues) filling in the issue template. We'll take a look as soon as possible. 115 116 ## Contributing 117 118 Please do not submit PRs against this package. It is generated from our OpenAPI definitions - [Please open an issue instead!](https://github.com/muxinc/mux-go/issues) 119 120 ## License 121 122 [MIT License.](LICENSE) Copyright 2019 Mux, Inc.