Categorygithub.com/nrdcg/bunny-go
modulepackage
0.0.0-20240207213615-dde5bf4577a3
Repository: https://github.com/nrdcg/bunny-go.git
Documentation: pkg.go.dev

# README

bunny-go

CI Go Report Card GoDoc

bunny-go is an unofficial Go package to interact with the Bunny.net HTTP API.

It aims to be a low-level API that represents the Bunny API as close as possible.

The package only deviates from the API when it is necessary to prevent confusions.

Features

The following API Endpoints are supported:

  • bunny.net API
    • Billing
    • Pull Zone
      • Add
      • Update
      • Delete
      • Get
      • List
      • Delete Edge Rule
      • Add/Update Edge Rule
      • Set Edge Rule Enabled
      • Get Statistics
      • Purge Cache
      • Load Free Certificate
      • Add Custom Certificate
      • Remove Certificate
      • Add Custom Hostname
      • Remove Custom Hostname
      • Set Force SSL
      • Reset Token Key
      • Add Allowed Referer
      • Remove Allowed Referer
      • Add Blocked Referer
      • Remove Blocked Referer
      • Add Blocked IP
      • Remove Blocked IP
    • Purge
    • Statistics
    • Storage Zone
      • List Storage Zones
      • Add Storage Zone
      • Get Storage Zone
      • Update Storage Zone
      • Delete Storage Zone
      • Reset Password
      • Reset Read-Only Password
  • User
  • DNS Zone
    • List DNS Zones
    • Add DNS Zone
    • Get DNS Zone
    • Update DNS Zones
    • Delete DNS Zone
    • Export DNS Zone
    • Get DNS Query Statistics
    • Add DNS Record
    • Update DNS Record
    • Delete DNS Record
    • Recheck DNS Configuration
    • Dismiss DNS Configuration Notice
    • Import DNS Records
  • Stream Video Library
    • List Video Libraries
    • Add Video Library
    • Get Video Library
    • Update Video Library
    • Delete Video Library
    • Reset Password
    • Reset Password
    • Add Watermark
    • Delete Watermark
    • Add Allowed Referer
    • Remove Allowed Referer
    • Add Blocked Referer
    • Remove Blocked Referer
  • Edge Storage API

Example

See client_example_test.go

Design Principles

  • URL parameters are always passed by value as method parameter.
  • Data that is sent in the HTTP body is passed as struct pointer to API methods.
  • Pointers instead of values are used to represent fields in body message structs.
    The bunny.net API does not define which values are assumed if a field is omitted in a request. Using pointers allows to distinguish between empty fields and Golang's default values for types. This prevents discrepancy between the interpretation of missing fields of the bunny.net API and bunny-go. Without using pointers it is for example not possible to distinguish between a missing integer field in a JSON message and an integer that has a 0 value.
  • Message field names should be as close as possible to the JSON message field names. Exception are permitted if the field in the JSON messages are inconsistent and different names are used in the API for the same setting. If names are inconsistent, the variant that is closer to the naming in the Bunny.Net Admin Panel should be chosen. The exception must be documented in the godoc.

Development

Running Integration Tests

To run the integration test a Bunny.Net API Key is required.
The integration tests will create, modify and delete resources on your Bunny.Net account. Therefore it is strongly recommended to use a Bunny.Net account that is not used in production environments.
Bunny.Net might charge your account for certain API operations.
The integrationtest should remove all resources that they create. It can happen that cleaning up the resources fails and the account will contain test leftovers.

export BUNNY_API_KEY=MY-API-KEY
make integrationtests

Status

The package is under initial development and should be considered as unstable.

# Functions

NewClient returns a new bunny.net API client.
WithHTTPRequestLogger is an option to log all sent out HTTP-Request via a log function.
WithHTTPResponseLogger is an option to log all received HTTP-Responses via a log function.
WithLogger is an option to set a log function to which informal and warning messages will be logged.
WithUserAgent is an option to specify the value of the User-Agent HTTP Header.

# Constants

AccessKeyHeaderKey is the name of the HTTP header that contains the Bunny API key.
BaseURL is the base URL of the Bunny CDN HTTP API.
DefaultPaginationPage is the default value that is used for PaginationOptions.Page if it is unset.
DefaultPaginationPerPage is the default value that is used for PaginationOptions.PerPage if it is unset.
DefaultUserAgent is the default value of the sent HTTP User-Agent header.
Constants for the Type field of a DNS Record.
Constants for the Type field of a DNS Record.
Constants for the Type field of a DNS Record.
Constants for the Type field of a DNS Record.
Constants for the Type field of a DNS Record.
Constants for the Type field of a DNS Record.
Constants for the Type field of a DNS Record.
Bunny.NET Pull Zone custom record.
Bunny.NET Redirect custom record.
Bunny.NET Script custom record.
Constants for the Type field of a DNS Record.
Constants for the Type field of a DNS Record.
Constants for the ActionType fields of an EdgeRule.
Constants for the ActionType fields of an EdgeRule.
Constants for the ActionType fields of an EdgeRule.
Constants for the ActionType fields of an EdgeRule.
Constants for the ActionType fields of an EdgeRule.
Constants for the ActionType fields of an EdgeRule.
Constants for the ActionType fields of an EdgeRule.
Constants for the ActionType fields of an EdgeRule.
Constants for the ActionType fields of an EdgeRule.
Constants for the ActionType fields of an EdgeRule.
Constants for the ActionType fields of an EdgeRule.
Constants for the ActionType fields of an EdgeRule.
Constants for the ActionType fields of an EdgeRule.
Constants for the ActionType fields of an EdgeRule.
Constants for the ActionType fields of an EdgeRule.
Constants for the ActionType fields of an EdgeRule.
Constants for the Type field of an EdgeRuleTrigger.
Constants for the Type field of an EdgeRuleTrigger.
Constants for the Type field of an EdgeRuleTrigger.
Constants for the Type field of an EdgeRuleTrigger.
Constants for the Type field of an EdgeRuleTrigger.
Constants for the Type field of an EdgeRuleTrigger.
Constants for the Type field of an EdgeRuleTrigger.
Constants for the Type field of an EdgeRuleTrigger.
Constants for the Type field of an EdgeRuleTrigger.
Constants for the Type field of an EdgeRuleTrigger.
Constants for the values of the PatternMatchingType of EdgeRuleTrigger and TriggerMatchingType of an EdgeRule.
Constants for the values of the PatternMatchingType of EdgeRuleTrigger and TriggerMatchingType of an EdgeRule.
Constants for the values of the PatternMatchingType of EdgeRuleTrigger and TriggerMatchingType of an EdgeRule.
Constants for the Type fields of a Pull Zone.
Constants for the Type fields of a Pull Zone.

# Structs

AddCustomHostnameOptions represents the message that is sent to the Add Custom Hostname API Endpoint.
AddOrUpdateDNSRecordOptions represents the message that is sent to the Add DNS Record API Endpoint.
AddOrUpdateEdgeRuleOptions is the message that is sent to the Add/Update Edge Rule API Endpoint.
APIError represents an error that is returned by some Bunny API endpoints on failures.
AuthenticationError represents an Unauthorized (401) HTTP error.
Client is a Bunny CDN HTTP API Client.
DNSRecord represents individual DNS records for a DNS Zone.
DNSZone represents the response of the List and Get DNS Zone API endpoint.
DNSZoneService communicates with the /dnszone API endpoint.
DNSZoneUpdateOptions represents the request parameters for the Update DNS Zone API endpoint.
EdgeRule represents an EdgeRule.
EdgeRuleTrigger represents the values of the Trigger field of an EdgeRule.
EnvironmentalVariable represents the environmental variables attached to a DNS record.
Hostname represents a Hostname returned from the Get and List Pull Zone API Endpoints.
HTTPError is returned by the Client when an unsuccessful HTTP response was returned or a response could not be processed.
IPGeoLocationInfo represents the geolocation data attached to a DNS record.
PaginationOptions specifies optional parameters for List APIs.
PaginationReply represents the pagination information contained in a List API endpoint response.
PullZone represents the response of the List and Get Pull Zone API endpoint.
PullZoneAddCustomCertificateOptions are the request parameters for the Add Custom Certificate API Endpoint.
PullZoneAddOptions are the request parameters for the Get Pull Zone API endpoint.
PullZoneService communicates with the /pullzone API endpoint.
PullZoneUpdateOptions represents the request parameters for the Update Pull Zone API endpoint.
RemoveCertificateOptions represents the request parameters for the Remove Certificate API Endpoint.
RemoveCustomHostnameOptions represents the message that is sent to the Remove Custom Hostname API Endpoint.
SetEdgeRuleEnabledOptions represents the message that is sent to Add/Update Edge Rule endpoint.
SetForceSSLOptions represents the message is to the Set Force SSL Endpoint.
StorageZone represents the response of the List and Get Storage Zone API endpoint.
StorageZoneAddOptions are the request parameters for the Get Storage Zone API endpoint.
StorageZoneService communicates with the /storagezone API endpoint.
StorageZoneUpdateOptions represents the request parameters for the Update Storage Zone API endpoint.
VideoLibrary represents the response of the List and Get Video Library API endpoint.
VideoLibraryAddOptions are the request parameters for the Get Video Library API endpoint.
VideoLibraryGetOpts represents optional query parameters available when Getting or Listing Video Libraries.
VideoLibraryListOpts represents both PaginationOptions and the other optional query parameters of the List endpoint.
VideoLibraryService communicates with the /videolibrary API endpoint.
VideoLibraryUpdateOptions represents the request parameters for the Update Storage Zone API endpoint.

# Type aliases

Logf is a log function signature.
Option is a type for Client options.