Documentation
¶
Overview ¶
Package bandwidth represents the SiteHost `/bandwidth` API endpoint.
Index ¶
- type Client
- func (s *Client) GetUsageByDay(ctx context.Context, opt UsageOptions) (response UsageResponse, err error)
- func (s *Client) GetUsageByMonth(ctx context.Context, opt UsageOptions) (response UsageResponse, err error)
- func (s *Client) GetUsageByYear(ctx context.Context, opt UsageOptions) (response UsageResponse, err error)
- func (s *Client) GetUsageSummary(ctx context.Context) (response UsageResponse, err error)
- func (s *Client) ListIPAddresses(ctx context.Context) (response ListIPAddressesResponse, err error)
- func (s *Client) ListResources(ctx context.Context) (response ListResourcesResponse, err error)
- type ListIPAddressesResponse
- type ListResourcesResponse
- type Number
- type ResourceGroup
- type ResourceQuota
- type TrafficStats
- type UsageOptions
- type UsageResponse
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a Service to work with API Jobs.
func (*Client) GetUsageByDay ¶ added in v0.7.0
func (s *Client) GetUsageByDay(ctx context.Context, opt UsageOptions) (response UsageResponse, err error)
GetUsageByDay retrieves the daily bandwidth usage for a single IP via "bandwidth/get_usage_by_day.json". Period keys in the response are "YYYY-MM-DD". The IPAddr field of opt is required and must be in CIDR form (e.g. "203.0.113.10/32").
func (*Client) GetUsageByMonth ¶ added in v0.7.0
func (s *Client) GetUsageByMonth(ctx context.Context, opt UsageOptions) (response UsageResponse, err error)
GetUsageByMonth retrieves the monthly bandwidth usage for a single IP via "bandwidth/get_usage_by_month.json". Period keys in the response are "YYYY-MM". The IPAddr field of opt is required and must be in CIDR form (e.g. "203.0.113.10/32").
func (*Client) GetUsageByYear ¶ added in v0.7.0
func (s *Client) GetUsageByYear(ctx context.Context, opt UsageOptions) (response UsageResponse, err error)
GetUsageByYear retrieves the annual bandwidth usage for a single IP via "bandwidth/get_usage_by_year.json". Period keys in the response are "YYYY". The IPAddr field of opt is required and must be in CIDR form (e.g. "203.0.113.10/32").
func (*Client) GetUsageSummary ¶ added in v0.7.0
func (s *Client) GetUsageSummary(ctx context.Context) (response UsageResponse, err error)
GetUsageSummary retrieves the current-month bandwidth usage summary across all IPs allocated to the authenticated client via "bandwidth/get_usage_summary.json". Period keys in the response are "YYYY-MM" (current month).
func (*Client) ListIPAddresses ¶
func (s *Client) ListIPAddresses(ctx context.Context) (response ListIPAddressesResponse, err error)
ListIPAddresses fetchs a list of IP addresses and subnets.
func (*Client) ListResources ¶ added in v0.7.0
func (s *Client) ListResources(ctx context.Context) (response ListResourcesResponse, err error)
ListResources retrieves the per-client resource quota groups via "bandwidth/list_resources.json". Each group contains one or more quotas with total / used / available unit counts and the list of objects (servers) consuming each.
type ListIPAddressesResponse ¶
type ListIPAddressesResponse struct {
models.APIResponse
Return map[string]models.IPAddress `json:"return"`
}
ListIPAddressesResponse represents a response from listing IP addresses with the `/bandwidth/get_ip_list.json` endpoint.
**Wire-shape quirk** (verified live): when the account has no allocated IPs, "return" is the JSON array `[]`, not the empty object `{}`. Custom UnmarshalJSON tolerates both forms.
func (*ListIPAddressesResponse) UnmarshalJSON ¶ added in v0.7.0
func (r *ListIPAddressesResponse) UnmarshalJSON(data []byte) error
UnmarshalJSON tolerates the empty-array form the API returns when the account has no allocated IPs. See type comment.
type ListResourcesResponse ¶ added in v0.7.0
type ListResourcesResponse struct {
Return []ResourceGroup `json:"return"`
models.APIResponse
}
ListResourcesResponse represents the response from list_resources.
type Number ¶ added in v0.7.0
type Number float64
Number tolerates the bandwidth API's mixed JSON-string / JSON-number serialisation of numeric fields. Within a single list_resources response, used_units comes back as a string (`"783"`) when usage is non-zero and a JSON number (`0`) when usage is zero, in the same account. Decoding into a fixed Go type breaks for any account with at least one zero-used quota — a common shape, not an edge case.
Number accepts either form and stores the value as float64.
func (*Number) UnmarshalJSON ¶ added in v0.7.0
UnmarshalJSON accepts either a JSON string or JSON number.
type ResourceGroup ¶ added in v0.7.0
type ResourceGroup struct {
ClientID string `json:"client_id"`
GroupID string `json:"group_id"`
GroupName string `json:"group_name"`
Quotas []ResourceQuota `json:"quotas"`
}
ResourceGroup represents a per-client resource quota group.
type ResourceQuota ¶ added in v0.7.0
type ResourceQuota struct {
AttributeID string `json:"attribute_id"`
AttributeName string `json:"attribute_name"`
AttributeUnit string `json:"attribute_unit"`
AttributeType string `json:"attribute_type"`
TotalUnits Number `json:"total_units"`
UsedUnits Number `json:"used_units"`
AvailableUnits int `json:"available_units"`
Objects []string `json:"objects"`
}
ResourceQuota is a single quota entry inside a resource group. AvailableUnits is returned as a number (and may be negative when over-quota).
TotalUnits and UsedUnits use Number because the API mixes JSON-string and JSON-number forms within a single response — see the Number type documentation.
type TrafficStats ¶ added in v0.7.0
type TrafficStats struct {
PeakIn float64 `json:"peak_in"`
OffpeakIn float64 `json:"offpeak_in"`
PeakOut float64 `json:"peak_out"`
OffpeakOut float64 `json:"offpeak_out"`
}
TrafficStats is a single traffic class's peak/offpeak in/out counters in MB. Used inside the usage endpoints' nested map.
type UsageOptions ¶ added in v0.7.0
type UsageOptions struct {
IPAddr string `url:"ip_addr"`
}
UsageOptions identifies an IP address (in CIDR form, e.g. "203.0.113.10/32") for the bandwidth usage endpoints. Used by GetUsageByDay, GetUsageByMonth, and GetUsageByYear.
type UsageResponse ¶ added in v0.7.0
type UsageResponse struct {
Return map[string]map[string]map[string]TrafficStats `json:"return"`
models.APIResponse
}
UsageResponse is the shared response shape for the usage endpoints (get_usage_summary, get_usage_by_day, by_month, by_year). The Return map nests three levels:
ip-CIDR → period-key → traffic-class → TrafficStats
Where:
- ip-CIDR is the address with prefix (e.g. "203.0.113.10/32")
- period-key format depends on the endpoint: summary → "YYYY-MM" (current month) by_day → "YYYY-MM-DD" by_month → "YYYY-MM" by_year → "YYYY"
- traffic-class is "DOMESTIC" or "INTERNATIONAL"
**Wire-shape quirk** (verified live): when the account has no bandwidth history (or no rows in the queried window), "return" is the JSON array `[]`, not the empty object `{}`. Custom UnmarshalJSON tolerates both forms.
func (*UsageResponse) UnmarshalJSON ¶ added in v0.7.0
func (r *UsageResponse) UnmarshalJSON(data []byte) error
UnmarshalJSON tolerates the empty-array form the API returns when the account has no bandwidth history in the queried window. See type comment.