consul/vendor/github.com/linode/linodego
R.B. Boyer fdb6b80672
Switch to go 1.13.7 (#7262)
- You can no longer cross submodule boundaries with ./... in go
  subcommands like `go list` or `go test`. The makefile and CI scripts
  were updated accordingly.

- Also of note: `go mod vendor` now omits things build ignored.
2020-02-12 10:15:24 -06:00
..
.gitignore Bump go-discover to support EC2 Metadata Service v2 (#6865) 2019-12-04 11:59:16 -05:00
.travis.yml Bump go-discover to support EC2 Metadata Service v2 (#6865) 2019-12-04 11:59:16 -05:00
API_SUPPORT.md Bump go-discover to support EC2 Metadata Service v2 (#6865) 2019-12-04 11:59:16 -05:00
CHANGELOG.md Bump go-discover to support EC2 Metadata Service v2 (#6865) 2019-12-04 11:59:16 -05:00
Gopkg.lock Bump go-discover to support EC2 Metadata Service v2 (#6865) 2019-12-04 11:59:16 -05:00
Gopkg.toml Bump go-discover to support EC2 Metadata Service v2 (#6865) 2019-12-04 11:59:16 -05:00
LICENSE Bump go-discover to support EC2 Metadata Service v2 (#6865) 2019-12-04 11:59:16 -05:00
Makefile Bump go-discover to support EC2 Metadata Service v2 (#6865) 2019-12-04 11:59:16 -05:00
README.md Bump go-discover to support EC2 Metadata Service v2 (#6865) 2019-12-04 11:59:16 -05:00
account.go Bump go-discover to support EC2 Metadata Service v2 (#6865) 2019-12-04 11:59:16 -05:00
account_events.go Bump go-discover to support EC2 Metadata Service v2 (#6865) 2019-12-04 11:59:16 -05:00
account_invoices.go Bump go-discover to support EC2 Metadata Service v2 (#6865) 2019-12-04 11:59:16 -05:00
account_notifications.go Bump go-discover to support EC2 Metadata Service v2 (#6865) 2019-12-04 11:59:16 -05:00
account_users.go Bump go-discover to support EC2 Metadata Service v2 (#6865) 2019-12-04 11:59:16 -05:00
client.go Bump go-discover to support EC2 Metadata Service v2 (#6865) 2019-12-04 11:59:16 -05:00
domain_records.go Bump go-discover to support EC2 Metadata Service v2 (#6865) 2019-12-04 11:59:16 -05:00
domains.go Bump go-discover to support EC2 Metadata Service v2 (#6865) 2019-12-04 11:59:16 -05:00
env.sample Bump go-discover to support EC2 Metadata Service v2 (#6865) 2019-12-04 11:59:16 -05:00
errors.go Bump go-discover to support EC2 Metadata Service v2 (#6865) 2019-12-04 11:59:16 -05:00
images.go Bump go-discover to support EC2 Metadata Service v2 (#6865) 2019-12-04 11:59:16 -05:00
instance_configs.go Bump go-discover to support EC2 Metadata Service v2 (#6865) 2019-12-04 11:59:16 -05:00
instance_disks.go Bump go-discover to support EC2 Metadata Service v2 (#6865) 2019-12-04 11:59:16 -05:00
instance_ips.go Bump go-discover to support EC2 Metadata Service v2 (#6865) 2019-12-04 11:59:16 -05:00
instance_snapshots.go Bump go-discover to support EC2 Metadata Service v2 (#6865) 2019-12-04 11:59:16 -05:00
instance_volumes.go Bump go-discover to support EC2 Metadata Service v2 (#6865) 2019-12-04 11:59:16 -05:00
instances.go Bump go-discover to support EC2 Metadata Service v2 (#6865) 2019-12-04 11:59:16 -05:00
kernels.go Bump go-discover to support EC2 Metadata Service v2 (#6865) 2019-12-04 11:59:16 -05:00
longview.go Bump go-discover to support EC2 Metadata Service v2 (#6865) 2019-12-04 11:59:16 -05:00
longview_subscriptions.go Bump go-discover to support EC2 Metadata Service v2 (#6865) 2019-12-04 11:59:16 -05:00
managed.go Bump go-discover to support EC2 Metadata Service v2 (#6865) 2019-12-04 11:59:16 -05:00
network_ips.go Bump go-discover to support EC2 Metadata Service v2 (#6865) 2019-12-04 11:59:16 -05:00
network_pools.go Bump go-discover to support EC2 Metadata Service v2 (#6865) 2019-12-04 11:59:16 -05:00
network_ranges.go Bump go-discover to support EC2 Metadata Service v2 (#6865) 2019-12-04 11:59:16 -05:00
nodebalancer.go Bump go-discover to support EC2 Metadata Service v2 (#6865) 2019-12-04 11:59:16 -05:00
nodebalancer_config_nodes.go Bump go-discover to support EC2 Metadata Service v2 (#6865) 2019-12-04 11:59:16 -05:00
nodebalancer_configs.go Bump go-discover to support EC2 Metadata Service v2 (#6865) 2019-12-04 11:59:16 -05:00
pagination.go Bump go-discover to support EC2 Metadata Service v2 (#6865) 2019-12-04 11:59:16 -05:00
profile.go Bump go-discover to support EC2 Metadata Service v2 (#6865) 2019-12-04 11:59:16 -05:00
profile_sshkeys.go Bump go-discover to support EC2 Metadata Service v2 (#6865) 2019-12-04 11:59:16 -05:00
profile_tokens.go Bump go-discover to support EC2 Metadata Service v2 (#6865) 2019-12-04 11:59:16 -05:00
regions.go Bump go-discover to support EC2 Metadata Service v2 (#6865) 2019-12-04 11:59:16 -05:00
resources.go Bump go-discover to support EC2 Metadata Service v2 (#6865) 2019-12-04 11:59:16 -05:00
stackscripts.go Bump go-discover to support EC2 Metadata Service v2 (#6865) 2019-12-04 11:59:16 -05:00
support.go Bump go-discover to support EC2 Metadata Service v2 (#6865) 2019-12-04 11:59:16 -05:00
tags.go Bump go-discover to support EC2 Metadata Service v2 (#6865) 2019-12-04 11:59:16 -05:00
types.go Bump go-discover to support EC2 Metadata Service v2 (#6865) 2019-12-04 11:59:16 -05:00
util.go Bump go-discover to support EC2 Metadata Service v2 (#6865) 2019-12-04 11:59:16 -05:00
volumes.go Bump go-discover to support EC2 Metadata Service v2 (#6865) 2019-12-04 11:59:16 -05:00
waitfor.go Bump go-discover to support EC2 Metadata Service v2 (#6865) 2019-12-04 11:59:16 -05:00

README.md

linodego

Build Status 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 := NewListOptions(0,"")
kernels, err := linodego.ListKernels(context.Background(), opts)
// len(kernels) == 218

Single Page

opts := NewListOptions(2,"")
// or opts := 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 := ListOptions{Filter: "{\"mine\":true}"}
// or opts := NewListOptions(0, "{\"mine\":true}")
stackscripts, err := linodego.ListStackscripts(context.Background(), opts)

Error Handling

Getting Single Entities

linode, err := linodego.GetLinode(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.ListLinodes(context.Background(), 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.ListLinodes(context.Background(), 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 test to run the unit tests. This is the same as running go test except that make test will execute the tests while playing back API response fixtures that were recorded during a previous development build.

go test can be used without the fixtures. Copy env.sample to .env and configure your persistent test settings, including an API token.

go test -short can be used to run live API tests that do not require an account token.

This will be simplified in future versions.

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