# README
Akamai OPEN EdgeGrid for GoLang
This library implements an Authentication handler for net/http that provides the Akamai OPEN Edgegrid Authentication scheme. For more information visit the Akamai OPEN Developer Community.
Installation
This package uses dep
to manage to dependencies and installation. To install dep
, see the dep
install documentation
$ dep ensure -add github.com/akamai/AkamaiOPEN-edgegrid-golang
Usage
GET Example:
package main
import (
"fmt"
"io/ioutil"
"net/http"
"github.com/akamai/AkamaiOPEN-edgegrid-golang/client-v1"
"github.com/akamai/AkamaiOPEN-edgegrid-golang/edgegrid"
)
func main() {
config, _ := edgegrid.Init("~/.edgerc", "default")
// Retrieve all locations for diagnostic tools
req, _ := client.NewRequest(config, "GET", "/diagnostic-tools/v1/locations", nil)
resp, _ := client.Do(config, req)
defer resp.Body.Close()
byt, _ := ioutil.ReadAll(resp.Body)
fmt.Println(string(byt))
}
Parameter Example:
package main
import (
"fmt"
"io/ioutil"
"net/http"
"github.com/akamai/AkamaiOPEN-edgegrid-golang/client-v1"
"github.com/akamai/AkamaiOPEN-edgegrid-golang/edgegrid"
)
func main() {
config, _ := edgegrid.Init("~/.edgerc", "default")
// Retrieve dig information for specified location
req, _ := client.NewRequest(config, "GET", "/diagnostic-tools/v1/dig", nil)
q := req.URL.Query()
q.Add("hostname", "developer.akamai.com")
q.Add("queryType", "A")
q.Add("location", "Auckland, New Zealand")
req.URL.RawQuery = q.Encode()
resp, _ := client.Do(config, req)
defer resp.Body.Close()
byt, _ := ioutil.ReadAll(resp.Body)
fmt.Println(string(byt))
}
POST Example:
package main
import (
"fmt"
"io/ioutil"
"net/http"
"github.com/akamai/AkamaiOPEN-edgegrid-golang/client-v1"
"github.com/akamai/AkamaiOPEN-edgegrid-golang/edgegrid"
)
func main() {
config, _ := edgegrid.Init("~/.edgerc", "default")
// Acknowledge a map
req, _ := client.NewRequest(config, "POST", "/siteshield/v1/maps/1/acknowledge", nil)
resp, _ := client.Do(config, req)
defer resp.Body.Close()
byt, _ := ioutil.ReadAll(resp.Body)
fmt.Println(string(byt))
}
PUT Example:
package main
import (
"fmt"
"io/ioutil"
"net/http"
"github.com/akamai/AkamaiOPEN-edgegrid-golang/client-v1"
"github.com/akamai/AkamaiOPEN-edgegrid-golang/edgegrid"
)
func main() {
config, _ := edgegrid.Init("~/.edgerc", "default")
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}")
// Update a Network List
req, _ := client.NewJSONRequest(config, "PUT", "/network-list/v1/network_lists/unique-id?extended=extended", body)
resp, _ := client.Do(config, req)
defer resp.Body.Close()
byt, _ := ioutil.ReadAll(resp.Body)
fmt.Println(string(byt))
}
Alternatively, your program can read it from config struct.
package main
import (
"fmt"
"io/ioutil"
"net/http"
"github.com/akamai/AkamaiOPEN-edgegrid-golang/client-v1"
"github.com/akamai/AkamaiOPEN-edgegrid-golang/edgegrid"
)
func main() {
config := edgegrid.Config{
Host : "xxxxxx.luna.akamaiapis.net",
ClientToken: "xxxx-xxxxxxxxxxx-xxxxxxxxxxx",
ClientSecret: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
AccessToken: "xxxx-xxxxxxxxxxx-xxxxxxxxxxx",
MaxBody: 1024,
HeaderToSign: []string{
"X-Test1",
"X-Test2",
"X-Test3",
},
Debug: false,
}
// Retrieve all locations for diagnostic tools
req, _ := client.NewRequest(config, "GET", fmt.Sprintf("https://%s/diagnostic-tools/v1/locations", config.Host), nil)
resp, _ := client.Do(config, req)
defer resp.Body.Close()
byt, _ := ioutil.ReadAll(resp.Body)
fmt.Println(string(byt))
}
Contribute
- Fork the repository to start making your changes to the master branch
- Send a pull request.
Author
Davey Shafik - Developer Evangelist @ Akamai Technologies Nick Juettner - Software Engineer @ Zalando SE
# Packages
No description provided by the author
No description provided by the author
No description provided by the author
Package client is a simple library for http.Client to sign Akamai OPEN Edgegrid API requests.
No description provided by the author
Package edgegrid allows you to sign http.Request's using the Akamai OPEN Edgegrid Signing Scheme.
An example Diagnostic Tools v1 API Client.
Package jsonhooks adds hooks that are automatically called before JSON marshaling (PreMarshalJSON) and after JSON unmarshaling (PostUnmarshalJSON).
Package papi provides a simple wrapper for the Akamai Property Manager API.
# Functions
AddRequestHeader sets the authorization header to use Akamai Open API
Deprecated: use github.com/akamai/AkamaiOPEN-edgegrid-golang/edgegrid.
Init initializes Config using first ENV variables, with fallback to .edgerc file
Deprecated: use github.com/akamai/AkamaiOPEN-edgegrid-golang/edgegrid.
InitConfig initializes Config using .edgerc files
Deprecated: Backwards compatible wrapper around InitEdgeRc which should be used instead.
InitEdgeRc initializes Config using an .edgerc (INI) configuration file
Deprecated: use github.com/akamai/AkamaiOPEN-edgegrid-golang/edgegrid.
InitEnv initializes Config using ENV variables
Deprecated: use github.com/akamai/AkamaiOPEN-edgegrid-golang/edgegrid.
New creates a new Client with a given Config
Deprecated: use github.com/akamai/AkamaiOPEN-edgegrid-golang/client.
NewClient creates a new Client
Deprecated: use github.com/akamai/AkamaiOPEN-edgegrid-golang/client.
# Structs
Client is a simple http.Client wrapper that transparently signs requests
Deprecated: use github.com/akamai/AkamaiOPEN-edgegrid-golang/client.
Config struct provides all the necessary fields to create authorization header, debug is optional
Deprecated: use github.com/akamai/AkamaiOPEN-edgegrid-golang/edgegrid.