packer-cn/vendor/github.com/linode/linodego
Charlie Kenney 70a2c7d364
upgrade linodego to v0.14.0 (#9395)
* upgrade linodego to v0.14.0

* fix builder/linode linter errors

* Update go.mod

Co-authored-by: Adrien Delorme <adrien.delorme@icloud.com>
2020-06-12 11:36:54 +02:00
..
internal upgrade linodego to v0.14.0 (#9395) 2020-06-12 11:36:54 +02:00
.gitignore update vendor/ for linode builder 2019-04-15 20:42:02 -04:00
.golangci.yml upgrade linodego to v0.14.0 (#9395) 2020-06-12 11:36:54 +02:00
.travis.yml upgrade linodego to v0.14.0 (#9395) 2020-06-12 11:36:54 +02:00
API_SUPPORT.md upgrade linodego to v0.14.0 (#9395) 2020-06-12 11:36:54 +02:00
CHANGELOG.md upgrade linodego to v0.14.0 (#9395) 2020-06-12 11:36:54 +02:00
LICENSE update vendor/ for linode builder 2019-04-15 20:42:02 -04:00
Makefile upgrade linodego to v0.14.0 (#9395) 2020-06-12 11:36:54 +02:00
README.md upgrade linodego to v0.14.0 (#9395) 2020-06-12 11:36:54 +02:00
account.go upgrade linodego to v0.14.0 (#9395) 2020-06-12 11:36:54 +02:00
account_events.go upgrade linodego to v0.14.0 (#9395) 2020-06-12 11:36:54 +02:00
account_invoices.go upgrade linodego to v0.14.0 (#9395) 2020-06-12 11:36:54 +02:00
account_notifications.go upgrade linodego to v0.14.0 (#9395) 2020-06-12 11:36:54 +02:00
account_oauth_client.go upgrade linodego to v0.14.0 (#9395) 2020-06-12 11:36:54 +02:00
account_payments.go upgrade linodego to v0.14.0 (#9395) 2020-06-12 11:36:54 +02:00
account_settings.go upgrade linodego to v0.14.0 (#9395) 2020-06-12 11:36:54 +02:00
account_users.go upgrade linodego to v0.14.0 (#9395) 2020-06-12 11:36:54 +02:00
client.go upgrade linodego to v0.14.0 (#9395) 2020-06-12 11:36:54 +02:00
domain_records.go upgrade linodego to v0.14.0 (#9395) 2020-06-12 11:36:54 +02:00
domains.go upgrade linodego to v0.14.0 (#9395) 2020-06-12 11:36:54 +02:00
env.sample update vendor/ for linode builder 2019-04-15 20:42:02 -04:00
errors.go upgrade linodego to v0.14.0 (#9395) 2020-06-12 11:36:54 +02:00
firewall_rules.go upgrade linodego to v0.14.0 (#9395) 2020-06-12 11:36:54 +02:00
firewalls.go upgrade linodego to v0.14.0 (#9395) 2020-06-12 11:36:54 +02:00
go.mod upgrade linodego to v0.14.0 (#9395) 2020-06-12 11:36:54 +02:00
go.sum upgrade linodego to v0.14.0 (#9395) 2020-06-12 11:36:54 +02:00
images.go upgrade linodego to v0.14.0 (#9395) 2020-06-12 11:36:54 +02:00
instance_configs.go upgrade linodego to v0.14.0 (#9395) 2020-06-12 11:36:54 +02:00
instance_disks.go upgrade linodego to v0.14.0 (#9395) 2020-06-12 11:36:54 +02:00
instance_ips.go upgrade linodego to v0.14.0 (#9395) 2020-06-12 11:36:54 +02:00
instance_snapshots.go upgrade linodego to v0.14.0 (#9395) 2020-06-12 11:36:54 +02:00
instance_stats.go upgrade linodego to v0.14.0 (#9395) 2020-06-12 11:36:54 +02:00
instance_volumes.go upgrade linodego to v0.14.0 (#9395) 2020-06-12 11:36:54 +02:00
instances.go upgrade linodego to v0.14.0 (#9395) 2020-06-12 11:36:54 +02:00
kernels.go update vendor/ for linode builder 2019-04-15 20:42:02 -04:00
lke_cluster_pools.go upgrade linodego to v0.14.0 (#9395) 2020-06-12 11:36:54 +02:00
lke_clusters.go upgrade linodego to v0.14.0 (#9395) 2020-06-12 11:36:54 +02:00
longview.go upgrade linodego to v0.14.0 (#9395) 2020-06-12 11:36:54 +02:00
longview_subscriptions.go upgrade linodego to v0.14.0 (#9395) 2020-06-12 11:36:54 +02:00
managed.go update vendor/ for linode builder 2019-04-15 20:42:02 -04:00
network_ips.go update vendor/ for linode builder 2019-04-15 20:42:02 -04:00
network_pools.go update vendor/ for linode builder 2019-04-15 20:42:02 -04:00
network_ranges.go update vendor/ for linode builder 2019-04-15 20:42:02 -04:00
nodebalancer.go upgrade linodego to v0.14.0 (#9395) 2020-06-12 11:36:54 +02:00
nodebalancer_config_nodes.go upgrade linodego to v0.14.0 (#9395) 2020-06-12 11:36:54 +02:00
nodebalancer_configs.go upgrade linodego to v0.14.0 (#9395) 2020-06-12 11:36:54 +02:00
nodebalancer_stats.go upgrade linodego to v0.14.0 (#9395) 2020-06-12 11:36:54 +02:00
object_storage_buckets.go upgrade linodego to v0.14.0 (#9395) 2020-06-12 11:36:54 +02:00
object_storage_clusters.go upgrade linodego to v0.14.0 (#9395) 2020-06-12 11:36:54 +02:00
object_storage_keys.go upgrade linodego to v0.14.0 (#9395) 2020-06-12 11:36:54 +02:00
pagination.go upgrade linodego to v0.14.0 (#9395) 2020-06-12 11:36:54 +02:00
profile.go upgrade linodego to v0.14.0 (#9395) 2020-06-12 11:36:54 +02:00
profile_sshkeys.go upgrade linodego to v0.14.0 (#9395) 2020-06-12 11:36:54 +02:00
profile_tokens.go upgrade linodego to v0.14.0 (#9395) 2020-06-12 11:36:54 +02:00
regions.go upgrade linodego to v0.14.0 (#9395) 2020-06-12 11:36:54 +02:00
resources.go upgrade linodego to v0.14.0 (#9395) 2020-06-12 11:36:54 +02:00
retries.go upgrade linodego to v0.14.0 (#9395) 2020-06-12 11:36:54 +02:00
stackscripts.go upgrade linodego to v0.14.0 (#9395) 2020-06-12 11:36:54 +02:00
support.go update vendor/ for linode builder 2019-04-15 20:42:02 -04:00
tags.go upgrade linodego to v0.14.0 (#9395) 2020-06-12 11:36:54 +02:00
types.go update vendor/ for linode builder 2019-04-15 20:42:02 -04:00
volumes.go upgrade linodego to v0.14.0 (#9395) 2020-06-12 11:36:54 +02:00
waitfor.go upgrade linodego to v0.14.0 (#9395) 2020-06-12 11:36:54 +02:00

README.md

linodego

Build Status Release GoDoc Go Report Card codecov

Go client for Linode REST v4 API

Installation

go get -u github.com/linode/linodego

API Support

Check API_SUPPORT.md for current support of the Linode v4 API endpoints.

** Note: This project will change and break until we release a v1.0.0 tagged version. Breaking changes in v0.x.x will be denoted with a minor version bump (v0.2.4 -> v0.3.0) **

Documentation

See godoc for a complete reference.

The API generally follows the naming patterns prescribed in the OpenAPIv3 document for Linode APIv4.

Deviations in naming have been made to avoid using "Linode" and "Instance" redundantly or inconsistently.

A brief summary of the features offered in this API client are shown here.

Examples

General Usage

package main

import (
	"context"
	"fmt"

	"github.com/linode/linodego"
	"golang.org/x/oauth2"

	"log"
	"net/http"
	"os"
)

func main() {
  apiKey, ok := os.LookupEnv("LINODE_TOKEN")
  if !ok {
    log.Fatal("Could not find LINODE_TOKEN, please assert it is set.")
  }
  tokenSource := oauth2.StaticTokenSource(&oauth2.Token{AccessToken: apiKey})

  oauth2Client := &http.Client{
    Transport: &oauth2.Transport{
      Source: tokenSource,
    },
  }

  linodeClient := linodego.NewClient(oauth2Client)
  linodeClient.SetDebug(true)
  
  res, err := linodeClient.GetInstance(context.Background(), 4090913)
  if err != nil {
    log.Fatal(err)
  }
  fmt.Printf("%v", res)
}

Pagination

Auto-Pagination Requests

kernels, err := linodego.ListKernels(context.Background(), nil)
// len(kernels) == 218

Or, use a page value of "0":

opts := linodego.NewListOptions(0,"")
kernels, err := linodego.ListKernels(context.Background(), opts)
// len(kernels) == 218

Single Page

opts := linodego.NewListOptions(2,"")
// or opts := linodego.ListOptions{PageOptions: &PageOptions: {Page: 2 }}
kernels, err := linodego.ListKernels(context.Background(), opts)
// len(kernels) == 100

ListOptions are supplied as a pointer because the Pages and Results values are set in the supplied ListOptions.

// opts.Results == 218

Filtering

opts := linodego.ListOptions{Filter: "{\"mine\":true}"}
// or opts := linodego.NewListOptions(0, "{\"mine\":true}")
stackscripts, err := linodego.ListStackscripts(context.Background(), opts)

Error Handling

Getting Single Entities

linode, err := linodego.GetInstance(context.Background(), 555) // any Linode ID that does not exist or is not yours
// linode == nil: true
// err.Error() == "[404] Not Found"
// err.Code == "404"
// err.Message == "Not Found"

Lists

For lists, the list is still returned as [], but err works the same way as on the Get request.

linodes, err := linodego.ListInstances(context.Background(), linodego.NewListOptions(0, "{\"foo\":bar}"))
// linodes == []
// err.Error() == "[400] [X-Filter] Cannot filter on foo"

Otherwise sane requests beyond the last page do not trigger an error, just an empty result:

linodes, err := linodego.ListInstances(context.Background(), linodego.NewListOptions(9999, ""))
// linodes == []
// err = nil

Writes

When performing a POST or PUT request, multiple field related errors will be returned as a single error, currently like:

// err.Error() == "[400] [field1] foo problem; [field2] bar problem; [field3] baz problem"

Tests

Run make testunit to run the unit tests.

Run make testint to run the integration tests. The integration tests use fixtures.

To update the test fixtures, run make fixtures. This will record the API responses into the fixtures/ directory. Be careful about committing any sensitive account details. An attempt has been made to sanitize IP addresses and dates, but no automated sanitization will be performed against fixtures/*Account*.yaml, for example.

To prevent disrupting unaffected fixtures, target fixture generation like so: make ARGS="-run TestListVolumes" fixtures.

Discussion / Help

Join us at #linodego on the gophers slack

License

MIT License