All Projects → linode → Linodego

linode / Linodego

Licence: mit
Go client for Linode REST v4 API

Programming Languages

go
31211 projects - #10 most used programming language
golang
3204 projects

Projects that are alternatives of or similar to Linodego

Api Php Client
PHP client of Akeneo PIM API
Stars: ✭ 56 (-26.32%)
Mutual labels:  api-client
Igdb
Go client for the Internet Game Database API
Stars: ✭ 65 (-14.47%)
Mutual labels:  api-client
Russianpost
SDK для работы с API Почты России (pochta.ru)
Stars: ✭ 72 (-5.26%)
Mutual labels:  api-client
Openapi Generator
OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
Stars: ✭ 10,634 (+13892.11%)
Mutual labels:  api-client
Redux Api Call
One declarative API to create reducers, action creators and selectors for any API calls
Stars: ✭ 63 (-17.11%)
Mutual labels:  api-client
Chump
The Best API Wrapper for Pushover.
Stars: ✭ 67 (-11.84%)
Mutual labels:  api-client
Quandl Python
Stars: ✭ 1,076 (+1315.79%)
Mutual labels:  api-client
Node Bitbucket
Bitbucket API client for Browser and Node.js
Stars: ✭ 73 (-3.95%)
Mutual labels:  api-client
Slacko
A neat interface for Slack
Stars: ✭ 64 (-15.79%)
Mutual labels:  api-client
Newsapi
A python wrapper for News API.
Stars: ✭ 71 (-6.58%)
Mutual labels:  api-client
Avenue
Wrapper around URLSession and URLSessionTask to enable seamless integration with Operation / OperationQueue.
Stars: ✭ 58 (-23.68%)
Mutual labels:  api-client
Mvvmdemo
MVVMDemo With ReactiveCocoa
Stars: ✭ 60 (-21.05%)
Mutual labels:  api-client
Simpleapiclient Ios
A configurable api client based on Alamofire4 and RxSwift4 for iOS
Stars: ✭ 68 (-10.53%)
Mutual labels:  api-client
Groupy
A simple yet powerful API wrapper for the GroupMe messaging service.
Stars: ✭ 57 (-25%)
Mutual labels:  api-client
Python2 Krakenex
(UNMAINTAINED) REST Exchange API for Kraken.com, Python 2
Stars: ✭ 72 (-5.26%)
Mutual labels:  api-client
Github
Ruby interface to GitHub API
Stars: ✭ 1,081 (+1322.37%)
Mutual labels:  api-client
Moneybird Php Client
PHP Client for Moneybird V2
Stars: ✭ 67 (-11.84%)
Mutual labels:  api-client
Kraken Node
Official Kraken.io module for Node.js
Stars: ✭ 76 (+0%)
Mutual labels:  api-client
Openvulnapi
Documentation and Tools for Cisco's PSIRT openVuln API
Stars: ✭ 73 (-3.95%)
Mutual labels:  api-client
Bigcommerce Api Ruby
Connect Ruby applications with the Bigcommerce Platform
Stars: ✭ 69 (-9.21%)
Mutual labels:  api-client

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: &linodego.PageOptions{Page: 2}, PageSize: 500}
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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].