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 Glide to manage to dependencies and installation. To install Glide, see the Glide install documentation
$ glide get 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
Nick Juettner - Software Engineer @ Zalando SE
Davey Shafik - Developer Evangelist @ Akamai Technologies
Documentation
¶
Overview ¶
Package edgegrid provides the Akamai OPEN Edgegrid Authentication scheme
Deprecated: use client-v1/client instead
Package edgegrid provides the Akamai OPEN Edgegrid Authentication scheme ¶
Deprecated: use edgegrid/config and edgegrid/signer instead
Index ¶
- func AddRequestHeader(c Config, req *http.Request) *http.Requestdeprecated
- type Clientdeprecated
- func (c *Client) Do(req *http.Request) (*Response, error)deprecated
- func (c *Client) Get(url string) (*Response, error)deprecated
- func (c *Client) Head(url string) (*Response, error)deprecated
- func (c *Client) NewJSONRequest(method, urlStr string, body interface{}) (*http.Request, error)deprecated
- func (c *Client) NewRequest(method, urlStr string, body interface{}) (*http.Request, error)deprecated
- func (c *Client) Post(url string, bodyType string, body interface{}) (*Response, error)deprecated
- func (c *Client) PostForm(url string, data url.Values) (*Response, error)deprecated
- func (c *Client) PostJSON(url string, data interface{}) (*Response, error)deprecated
- type Configdeprecated
- type JSONBodydeprecated
- type Responsedeprecated
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Client
deprecated
type Client struct { http.Client // Base URL for API requests. BaseURL *url.URL // User agent for client UserAgent string Config Config }
Client is a simple http.Client wrapper that transparently signs requests
Deprecated: use github.com/akamai/AkamaiOPEN-edgegrid-golang/client
func (*Client) NewJSONRequest
deprecated
NewJSONRequest creates an API request with JSON body. A relative URL can be provided in urlStr, which will be resolved to the BaseURL of the Client. If specified, the value pointed to by body is JSON encoded and included in as the request body.
Deprecated: use github.com/akamai/AkamaiOPEN-edgegrid-golang/client
func (*Client) NewRequest
deprecated
NewRequest creates an API request. A relative URL can be provided in urlStr, which will be resolved to the BaseURL of the Client. If specified, the value pointed to by body is JSON encoded and included in as the request body.
Deprecated: use github.com/akamai/AkamaiOPEN-edgegrid-golang/client
type Config
deprecated
type Config struct { Host string `ini:"host"` ClientToken string `ini:"client_token"` ClientSecret string `ini:"client_secret"` AccessToken string `ini:"access_token"` HeaderToSign []string `ini:"headers_to_sign"` MaxBody int `ini:"max_body"` Debug bool `ini:"debug"` }
Config struct provides all the necessary fields to create authorization header, debug is optional
Deprecated: use github.com/akamai/AkamaiOPEN-edgegrid-golang/edgegrid
func InitConfig
deprecated
func InitEdgeRc
deprecated
type Response
deprecated
Response is a Wrapper for http.Response
Deprecated: use github.com/akamai/AkamaiOPEN-edgegrid-golang/client
Directories
¶
Path | Synopsis |
---|---|
Package client is a simple library for http.Client to sign Akamai OPEN Edgegrid API requests
|
Package client is a simple library for http.Client to sign Akamai OPEN Edgegrid API requests |
Package edgegrid allows you to sign http.Request's using the Akamai OPEN Edgegrid Signing Scheme
|
Package edgegrid allows you to sign http.Request's using the Akamai OPEN Edgegrid Signing Scheme |
An example Diagnostic Tools v1 API Client
|
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 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
|
Package papi provides a simple wrapper for the Akamai Property Manager API |