go-selvpcclient: github.com/selectel/go-selvpcclient/selvpcclient/resell/v2/traffic Index | Files | Directories

package traffic

import "github.com/selectel/go-selvpcclient/selvpcclient/resell/v2/traffic"

Package traffic provides the ability to retrieve traffic data through the Resell v2 API.

Example of getting domain traffic

domainTraffic, _, err := traffic.Get(ctx, resellClient)
if err != nil {
  log.Fatal(err)
}
for _, trafficData := range domainTraffic {
  fmt.Println(trafficData)
}

Index

Package Files

doc.go requests.go schemas.go

type Data Uses

type Data struct {
    // Start contains the start timestamp.
    Start time.Time `json:"-"`

    // Stop contains the stop timestamp.
    Stop time.Time `json:"-"`

    // Unit represents a unit that is used to represent traffic data.
    Unit string `json:"unit"`

    // Value contains traffic value for the specified period.
    Value int `json:"value"`
}

Data represents information about traffic in the specified period.

func (*Data) UnmarshalJSON Uses

func (r *Data) UnmarshalJSON(b []byte) error

UnmarshalJSON helps to unmarshal Data timestamp fields into the needed values.

type DomainTraffic Uses

type DomainTraffic struct {
    // DomainData contains data about domain traffic.
    DomainData []*Traffic `json:"domain"`
}

DomainTraffic represents domain traffic information.

func Get Uses

func Get(ctx context.Context, client *selvpcclient.ServiceClient) (*DomainTraffic, *selvpcclient.ResponseResult, error)

Get returns the domain traffic information.

func (*DomainTraffic) UnmarshalJSON Uses

func (result *DomainTraffic) UnmarshalJSON(b []byte) error

UnmarshalJSON implements custom unmarshalling method for the DomainTraffic type.

We need it to work with a JSON structure that the Resell v2 API responses with:

"domain": {
    "paid": {
        "start": "2018-04-01T00:00:00",
        "stop": "2018-04-30T23:59:59",
        "unit": "B",
        "value": 0
    },
    "prepaid": {
        "start": "2018-04-01T00:00:00",
        "stop": "2018-04-30T23:59:59",
        "unit": "B",
        "value": 3000000000000
    },
    "used": {
        "start": "2018-04-01T00:00:00",
        "stop": "2018-04-30T23:59:59",
        "unit": "B",
        "value": 658003816
    }
}

type Traffic Uses

type Traffic struct {
    // Type is a human-readable name of the type of traffic.
    Type string `json:"-"`

    // TrafficData contains information about traffic.
    TrafficData Data `json:"-"`
}

Traffic contains information about used and paid traffic.

Directories

PathSynopsis
testing

Package traffic imports 6 packages (graph) and is imported by 1 packages. Updated 2020-09-20. Refresh now. Tools for package owners.