README.md
1# Akamai OPEN EdgeGrid for GoLang v1
2
3[![Build Status](https://travis-ci.org/akamai/AkamaiOPEN-edgegrid-golang.svg?branch=master)](https://travis-ci.org/akamai/AkamaiOPEN-edgegrid-golang)
4[![GoDoc](https://godoc.org/github.com/akamai/AkamaiOPEN-edgegrid-golang?status.svg)](https://godoc.org/github.com/akamai/AkamaiOPEN-edgegrid-golang)
5[![Go Report Card](https://goreportcard.com/badge/github.com/akamai/AkamaiOPEN-edgegrid-golang)](https://goreportcard.com/report/github.com/akamai/AkamaiOPEN-edgegrid-golang)
6[![License](http://img.shields.io/:license-apache-blue.svg)](https://github.com/akamai/AkamaiOPEN-edgegrid-golang/blob/master/LICENSE)
7
8This library implements an Authentication handler for [net/http](https://golang.org/pkg/net/http/)
9that provides the [Akamai OPEN Edgegrid Authentication](https://developer.akamai.com/introduction/Client_Auth.html)
10scheme. For more information visit the [Akamai OPEN Developer Community](https://developer.akamai.com). This library
11has been released as a v1 library though future development will be on the v2 branch
12
13## Announcing Akamai OPEN EdgeGrid for GoLang v2 (release v2.0.0)
14
15The v2 branch of this module is under active development and provides a subset of Akamai APIs for use in the
16Akamai Terraform Provider. The v2 branch **does not yet** implement the full set of Akamai endpoints supported by the
170.x and 1.x releases.
18
19New users are encouraged to adopt v2 branch it is a simpler API wrapper with little to no business logic.
20
21Current direct users of this v0.9 library are recommended to continue to use the the v1 version as initialization
22and package structure has significantly changed in v2 and will require substantial work to migrate existing
23applications. Non-backwards compatible changes were made to improve the code quality and make the project more
24maintainable.
25
26## Usage of the v1 library
27
28GET Example:
29
30```go
31 package main
32
33import (
34 "fmt"
35 "io/ioutil"
36
37 "github.com/akamai/AkamaiOPEN-edgegrid-golang/client-v1"
38 "github.com/akamai/AkamaiOPEN-edgegrid-golang/edgegrid"
39)
40
41func main() {
42 config, _ := edgegrid.Init("~/.edgerc", "default")
43
44 // Retrieve all locations for diagnostic tools
45 req, _ := client.NewRequest(config, "GET", "/diagnostic-tools/v2/ghost-locations/available", nil)
46 resp, _ := client.Do(config, req)
47
48 defer resp.Body.Close()
49 byt, _ := ioutil.ReadAll(resp.Body)
50 fmt.Println(string(byt))
51}
52```
53
54Parameter Example:
55
56```go
57 package main
58
59import (
60 "fmt"
61 "io/ioutil"
62
63 "github.com/akamai/AkamaiOPEN-edgegrid-golang/client-v1"
64 "github.com/akamai/AkamaiOPEN-edgegrid-golang/edgegrid"
65)
66
67func main() {
68 config, _ := edgegrid.Init("~/.edgerc", "default")
69
70 // Retrieve dig information for specified location
71 req, _ := client.NewRequest(config, "GET", "/diagnostic-tools/v2/ghost-locations/zurich-switzerland/dig-info", nil)
72
73 q := req.URL.Query()
74 q.Add("hostName", "developer.akamai.com")
75 q.Add("queryType", "A")
76
77 req.URL.RawQuery = q.Encode()
78 resp, _ := client.Do(config, req)
79
80 defer resp.Body.Close()
81 byt, _ := ioutil.ReadAll(resp.Body)
82 fmt.Println(string(byt))
83}
84```
85
86POST Example:
87
88```go
89 package main
90
91 import (
92 "fmt"
93 "io/ioutil"
94 "net/http"
95
96 "github.com/akamai/AkamaiOPEN-edgegrid-golang/client-v1"
97 "github.com/akamai/AkamaiOPEN-edgegrid-golang/edgegrid"
98 )
99
100 func main() {
101 config, _ := edgegrid.Init("~/.edgerc", "default")
102
103 // Acknowledge a map
104 req, _ := client.NewRequest(config, "POST", "/siteshield/v1/maps/1/acknowledge", nil)
105 resp, _ := client.Do(config, req)
106
107 defer resp.Body.Close()
108 byt, _ := ioutil.ReadAll(resp.Body)
109 fmt.Println(string(byt))
110 }
111```
112
113PUT Example:
114
115```go
116 package main
117
118 import (
119 "fmt"
120 "io/ioutil"
121 "net/http"
122
123 "github.com/akamai/AkamaiOPEN-edgegrid-golang/client-v1"
124 "github.com/akamai/AkamaiOPEN-edgegrid-golang/edgegrid"
125 )
126
127 func main() {
128
129 config, _ := edgegrid.Init("~/.edgerc", "default")
130 body := []byte("{\n \"name\": \"Simple List\",\n \"type\": \"IP\",\n \"unique-id\": \"345_BOTLIST\",\n \"list\": [\n \"192.168.0.1\",\n \"192.168.0.2\",\n ],\n \"sync-point\": 0\n}")
131
132 // Update a Network List
133 req, _ := client.NewJSONRequest(config, "PUT", "/network-list/v1/network_lists/unique-id?extended=extended", body)
134 resp, _ := client.Do(config, req)
135
136 defer resp.Body.Close()
137 byt, _ := ioutil.ReadAll(resp.Body)
138 fmt.Println(string(byt))
139 }
140```
141
142Alternatively, your program can read it from config struct.
143
144```go
145 package main
146
147 import (
148 "fmt"
149 "io/ioutil"
150 "net/http"
151
152 "github.com/akamai/AkamaiOPEN-edgegrid-golang/client-v1"
153 "github.com/akamai/AkamaiOPEN-edgegrid-golang/edgegrid"
154 )
155
156 func main() {
157 config := edgegrid.Config{
158 Host : "xxxxxx.luna.akamaiapis.net",
159 ClientToken: "xxxx-xxxxxxxxxxx-xxxxxxxxxxx",
160 ClientSecret: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
161 AccessToken: "xxxx-xxxxxxxxxxx-xxxxxxxxxxx",
162 MaxBody: 1024,
163 HeaderToSign: []string{
164 "X-Test1",
165 "X-Test2",
166 "X-Test3",
167 },
168 Debug: false,
169 }
170
171 // Retrieve all locations for diagnostic tools
172 req, _ := client.NewRequest(config, "GET", fmt.Sprintf("https://%s/diagnostic-tools/v2/ghost-locations/available",config.Host), nil)
173 resp, _ := client.Do(config, req)
174
175 defer resp.Body.Close()
176 byt, _ := ioutil.ReadAll(resp.Body)
177 fmt.Println(string(byt))
178}
179```
180
181## Contribute
182
1831. Fork [the repository](https://github.com/akamai/AkamaiOPEN-edgegrid-golang) to start making your changes to the **master** branch
1842. Send a pull request.
185
186## Author
187
188[Davey Shafik](mailto:dshafik@akamai.com) - Developer Evangelist @ [Akamai Technologies](https://developer.akamai.com)
189[Nick Juettner](mailto:hello@juni.io) - Software Engineer @ [Zalando SE](https://tech.zalando.com/)
190
191