From 206b766d1a02b315d12e94039230fab8ca724487 Mon Sep 17 00:00:00 2001 From: Andre Marcelo-Tanner Date: Thu, 27 Sep 2018 14:21:29 +0800 Subject: [PATCH] Working WIP using Linode Go SDK --- .gitignore | 13 +++++++++++++ go.mod | 7 +++++++ go.sum | 8 ++++++++ main.go | 36 ++++++++++++++++++++++++++++++++++++ 4 files changed, 64 insertions(+) create mode 100644 .gitignore create mode 100644 go.mod create mode 100644 go.sum create mode 100644 main.go diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c4cdbf9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,13 @@ +# Binaries for programs and plugins +*.exe +*.exe~ +*.dll +*.so +*.dylib +ligo + +# Test binary, build with `go test -c` +*.test + +# Output of the go coverage tool, specifically when used with LiteIDE +*.out diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..2ef4824 --- /dev/null +++ b/go.mod @@ -0,0 +1,7 @@ +module github.com/kzap/ligo + +require ( + github.com/linode/linodego v0.5.2-0.20180916222121-15d4ab6c221b + golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be + gopkg.in/resty.v1 v1.9.1 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..489bc44 --- /dev/null +++ b/go.sum @@ -0,0 +1,8 @@ +github.com/linode/linodego v0.5.2-0.20180916222121-15d4ab6c221b h1:1oeOtCnxd4Fi9qWnUr0v/k1XURvWdEPGDyJLbHg4b6o= +github.com/linode/linodego v0.5.2-0.20180916222121-15d4ab6c221b/go.mod h1:ga11n3ivecUrPCHN0rANxKmfWBJVkOXfLMZinAbj2sY= +golang.org/x/net v0.0.0-20180611182652-db08ff08e862 h1:JZi6BqOZ+iSgmLWe6llhGrNnEnK+YB/MRkStwnEfbqM= +golang.org/x/net v0.0.0-20180611182652-db08ff08e862/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be h1:vEDujvNQGv4jgYKudGeI/+DAX4Jffq6hpD55MmoEvKs= +golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= +gopkg.in/resty.v1 v1.9.1 h1:Lq4EIBZ5e2J4ZWp22W2hVOYc0X1qwDDki/nNVchRbdw= +gopkg.in/resty.v1 v1.9.1/go.mod h1:vo52Hzryw9PnPHcJfPsBiFW62XhNx5OczbV9y+IMpgc= diff --git a/main.go b/main.go new file mode 100644 index 0000000..0aa6a04 --- /dev/null +++ b/main.go @@ -0,0 +1,36 @@ +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) +}