GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - linode/linodego: Go client for Linode REST v4 API

BranchesTags
Open more actions menu

Latest commit

 

History

1,346 Commits
1,346 Commits

Folders and files

NameName
Last commit message
Last commit date
.github
.github
 
 
docs
docs
 
 
e2e_scripts @ 6b71cb7
e2e_scripts @ 6b71cb7
 
 
internal
internal
 
 
k8s
k8s
 
 
scripts
scripts
 
 
test
test
 
 
.gitignore
.gitignore
 
 
.gitmodules
.gitmodules
 
 
.golangci.yml
.golangci.yml
 
 
AGENTS.md
AGENTS.md
 
 
CODEOWNERS
CODEOWNERS
 
 
LICENSE
LICENSE
 
 
Makefile
Makefile
 
 
README.md
README.md
 
 
account.go
account.go
 
 
account_agreements.go
account_agreements.go
 
 
account_availability.go
account_availability.go
 
 
account_betas.go
account_betas.go
 
 
account_child.go
account_child.go
 
 
account_events.go
account_events.go
 
 
account_invoices.go
account_invoices.go
 
 
account_logins.go
account_logins.go
 
 
account_maintenance.go
account_maintenance.go
 
 
account_notifications.go
account_notifications.go
 
 
account_oauth_client.go
account_oauth_client.go
 
 
account_payment_methods.go
account_payment_methods.go
 
 
account_payments.go
account_payments.go
 
 
account_promo_credits.go
account_promo_credits.go
 
 
account_service_transfer.go
account_service_transfer.go
 
 
account_settings.go
account_settings.go
 
 
account_tfa_optional_users.go
account_tfa_optional_users.go
 
 
account_transfer.go
account_transfer.go
 
 
account_user_grants.go
account_user_grants.go
 
 
account_users.go
account_users.go
 
 
base_types.go
base_types.go
 
 
betas.go
betas.go
 
 
client.go
client.go
 
 
client_monitor.go
client_monitor.go
 
 
client_test.go
client_test.go
 
 
config.go
config.go
 
 
config_test.go
config_test.go
 
 
databases.go
databases.go
 
 
domain_records.go
domain_records.go
 
 
domains.go
domains.go
 
 
entities.go
entities.go
 
 
env.sample
env.sample
 
 
errors.go
errors.go
 
 
errors_test.go
errors_test.go
 
 
filter.go
filter.go
 
 
filter_test.go
filter_test.go
 
 
firewall_devices.go
firewall_devices.go
 
 
firewall_rules.go
firewall_rules.go
 
 
firewall_rulesets.go
firewall_rulesets.go
 
 
firewall_templates.go
firewall_templates.go
 
 
firewalls.go
firewalls.go
 
 
go.mod
go.mod
 
 
go.sum
go.sum
 
 
go.work
go.work
 
 
helpers_iterator.go
helpers_iterator.go
 
 
iam.go
iam.go
 
 
image_sharegroups_consumer.go
image_sharegroups_consumer.go
 
 
image_sharegroups_producer.go
image_sharegroups_producer.go
 
 
images.go
images.go
 
 
instance_config_interfaces.go
instance_config_interfaces.go
 
 
instance_configs.go
instance_configs.go
 
 
instance_disks.go
instance_disks.go
 
 
instance_firewalls.go
instance_firewalls.go
 
 
instance_ips.go
instance_ips.go
 
 
instance_nodebalancers.go
instance_nodebalancers.go
 
 
instance_snapshots.go
instance_snapshots.go
 
 
instance_stats.go
instance_stats.go
 
 
instance_volumes.go
instance_volumes.go
 
 
instances.go
instances.go
 
 
interfaces.go
interfaces.go
 
 
kernels.go
kernels.go
 
 
lke_clusters.go
lke_clusters.go
 
 
lke_clusters_control_plane.go
lke_clusters_control_plane.go
 
 
lke_node_pools.go
lke_node_pools.go
 
 
lke_types.go
lke_types.go
 
 
locks.go
locks.go
 
 
logger.go
logger.go
 
 
longview.go
longview.go
 
 
longview_subscriptions.go
longview_subscriptions.go
 
 
maintenance_policy.go
maintenance_policy.go
 
 
monitor_alert_channels.go
monitor_alert_channels.go
 
 
monitor_alert_definitions.go
monitor_alert_definitions.go
 
 
monitor_api_services.go
monitor_api_services.go
 
 
monitor_dashboards.go
monitor_dashboards.go
 
 
monitor_log_destinations.go
monitor_log_destinations.go
 
 
monitor_log_streams.go
monitor_log_streams.go
 
 
monitor_metrics_definitions.go
monitor_metrics_definitions.go
 
 
monitor_services.go
monitor_services.go
 
 
monitor_services_create_token.go
monitor_services_create_token.go
 
 
mysql.go
mysql.go
 
 
network_ips.go
network_ips.go
 
 
network_pools.go
network_pools.go
 
 
network_ranges.go
network_ranges.go
 
 
network_reserved_ips.go
network_reserved_ips.go
 
 
network_transfer_prices.go
network_transfer_prices.go
 
 

Repository files navigation

linodego

Tests Release GoDoc Go Report Card

Go client for Linode REST v4 API

Installation

go get -u github.com/linode/linodego/v2

Documentation

See godoc for a complete reference.

For guidance on waiting for asynchronous API operations, see Event and Status Polling.

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"
	"log"
	"net/http"
	"os"

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

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, err := linodego.NewClient(oauth2Client)
	if err != nil {
		log.Fatal(err)
	}
	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

NOTES:

  • The ListOptions will be mutated by list endpoint functions.
  • Instances of ListOptions should NOT be shared across multiple list endpoint functions.
  • The resulting number of results and pages can be accessed through the user-supplied ListOptions instance.

Filtering

f := linodego.Filter{}
f.AddField(linodego.Eq, "mine", true)
fStr, err := f.MarshalJSON()
if err != nil {
    log.Fatal(err)
}
opts := linodego.NewListOptions(0, string(fStr))
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

Response Caching

By default, certain endpoints with static responses will be cached into memory. Endpoints with cached responses are identified in their accompanying documentation.

The default cache entry expiry time is 15 minutes. Certain endpoints may override this value to allow for more frequent refreshes (e.g. client.GetRegion(...)). The global cache expiry time can be customized using the client.SetGlobalCacheExpiration(...) method.

Response caching can be globally disabled or enabled for a client using the client.UseCache(...) method.

The global cache can be cleared and refreshed using the client.InvalidateCache() method.

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-unit to run the unit tests.

Run make test-int 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 TEST_ARGS="-run TestListVolumes" fixtures.

Discussion / Help

Join us at #linodego on the gophers slack

License

MIT License

About

Go client for Linode REST v4 API

Topics

api-clientgogolanglinodelinode-api

Resources

Readme
MIT license

Contributing

Contributing
Activity
Custom properties

Stars

167 stars

Watchers

10 watching

Forks

124 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.