Go

SDK for bunny.net 🐰

Go Reference

Installation

go get github.com/jlarmstrongiv/bunnysdkgo

Prerequisites

  • Please read the authentication guide to learn more about where to find your AccessKey and which AccessKey should be used for each client.
  • Please read the limitations guide to learn more about known limitations and bugs, such as nullable and optional typing.
  • Please read the supported endpoints guide to learn more about which endpoints are supported.

Quickstart

Create the client

package mainimport (  "os"  "github.com/jlarmstrongiv/bunnysdkgo")func main() {  accessKey := os.Getenv("BUNNY_ACCESS_KEY")  client, err := bunnysdkgo.CreateBunnyApiClient(&bunnysdkgo.CreateBunnyApiClientParameters{AccessKey: accessKey})  if err != nil {    panic(err)  }}

Create the pointer helper

Since there are no nullable versions of simple types in Go, pointers are used instead (reference).

Unfortunately, Go does not have an expression to create pointer to simple types (please upvote this issue).

func PointerOf[T any](t T) *T {  return &t}

Call a simple endpoint

fetch countries

package mainimport (  "context"  "fmt"  "os"  "github.com/jlarmstrongiv/bunnysdkgo")func main() {  accessKey := os.Getenv("BUNNY_ACCESS_KEY")  client, err := bunnysdkgo.CreateBunnyApiClient(&bunnysdkgo.CreateBunnyApiClientParameters{AccessKey: accessKey})  if err != nil {    panic(err)  }  countries, err := client.Country().Get(context.Background(), nil)  if err != nil {    panic(err)  }}

log countries

package mainimport (  "context"  "fmt"  "os"  "github.com/jlarmstrongiv/bunnysdkgo")func main() {  accessKey := os.Getenv("BUNNY_ACCESS_KEY")  client, err := bunnysdkgo.CreateBunnyApiClient(&bunnysdkgo.CreateBunnyApiClientParameters{AccessKey: accessKey})  if err != nil {    panic(err)  }  countries, err := client.Country().Get(context.Background(), nil)  if err != nil {    panic(err)  }  for i, country := range countries {    fmt.Printf("%d: %s\n", i, *country.GetName())  }}

Call a complex endpoint

The List Storage Zones endpoint is a more complex example that has required parameters.

fetch storage zones

package mainimport (  "context"  "fmt"  "os"  "github.com/jlarmstrongiv/bunnysdkgo"  "github.com/jlarmstrongiv/bunnysdkgo/bunny_api_client/storagezone"  abstractions "github.com/microsoft/kiota-abstractions-go")func PointerOf[T any](t T) *T {  return &t}func main() {  accessKey := os.Getenv("BUNNY_ACCESS_KEY")  client, err := bunnysdkgo.CreateBunnyApiClient(&bunnysdkgo.CreateBunnyApiClientParameters{AccessKey: accessKey})  if err != nil {    panic(err)  }  storageZones, err := client.Storagezone().Get(context.Background(), &abstractions.RequestConfiguration[storagezone.StoragezoneRequestBuilderGetQueryParameters]{    QueryParameters: &storagezone.StoragezoneRequestBuilderGetQueryParameters{      IncludeDeleted: PointerOf(true),      Page:           PointerOf(int32(1)),      PerPage:        PointerOf(int32(1000)),    },  })  if err != nil {    panic(err)  }}

log storage zones

package mainimport (  "context"  "fmt"  "os"  "github.com/jlarmstrongiv/bunnysdkgo"  "github.com/jlarmstrongiv/bunnysdkgo/bunny_api_client/storagezone"  abstractions "github.com/microsoft/kiota-abstractions-go")func PointerOf[T any](t T) *T {  return &t}func main() {  accessKey := os.Getenv("BUNNY_ACCESS_KEY")  client, err := bunnysdkgo.CreateBunnyApiClient(&bunnysdkgo.CreateBunnyApiClientParameters{AccessKey: accessKey})  if err != nil {    panic(err)  }  storageZones, err := client.Storagezone().Get(context.Background(), &abstractions.RequestConfiguration[storagezone.StoragezoneRequestBuilderGetQueryParameters]{    QueryParameters: &storagezone.StoragezoneRequestBuilderGetQueryParameters{      IncludeDeleted: PointerOf(true),      Page:           PointerOf(int32(1)),      PerPage:        PointerOf(int32(1000)),    },  })  if err != nil {    panic(err)  }  for i, storageZone := range storageZones.GetItems() {    fmt.Printf("%d: %s\n", i, *storageZone.GetName())  }}

All required parameters from the documentation are also required in the Bunny SDK. In this example, the required parameters are:

  • IncludeDeleted
  • Page
  • PerPage

Despite the documentation setting the default Page parameter to 0, the default value fails the validation, where the minimum page is 1.

If you receive a 400 Bad Request error, please double-check your parameters.

Go types

Most model and enum types are found in:

  • github.com/jlarmstrongiv/bunnysdkgo/<client>/<group>
  • github.com/jlarmstrongiv/bunnysdkgo/<client>/models/<group>
import (  "github.com/jlarmstrongiv/bunnysdkgo/bunny_api_client/storagezone")