File: edgegrid.go

package info (click to toggle)
golang-github-akamai-akamaiopen-edgegrid-golang 1.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 1,408 kB
  • sloc: sh: 532; makefile: 3
file content (41 lines) | stat: -rw-r--r-- 1,160 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package main

import (
	"fmt"
	"io/ioutil"
	"net/http"

	"github.com/akamai/AkamaiOPEN-edgegrid-golang/edgegrid"
)

func main() {
	client := http.Client{}

	/*
		Init will try to use the environment and fallback to .edgerc.

		This function will check in order:

		AKAMAI_{SECTION}_* environment variables
		if using the default section, AKAMAI_* environment variables
		the specified (or default if none) section in .edgerc
		if not using the default section, AKAMAI_* environment variables
		This new function is the recommended way for instantiating an instance.

		The environment variables are:

		AKAMAI_HOST or AKAMAI_{SECTION}_HOST
		AKAMAI_CLIENT_TOKEN or AKAMAI_{SECTION}_CLIENT_TOKEN
		AKAMAI_CLIENT_SECRET or AKAMAI_{SECTION}_CLIENT_SECRET
		AKAMAI_ACCESS_TOKEN or AKAMAI_{SECTION}_ACCESS_TOKEN
	*/
	config, err := edgegrid.InitEdgeRc("~/.edgerc", "default")

	if err == nil {
		req, _ := http.NewRequest("GET", fmt.Sprintf("https://%s/diagnostic-tools/v2/ghost-locations/available", config.Host), nil)
		req = edgegrid.AddRequestHeader(config, req)
		resp, _ := client.Do(req)
		byt, _ := ioutil.ReadAll(resp.Body)
		fmt.Println(string(byt))
	}
}