github.com/akamai/AkamaiOPEN-edgegrid-golang/v8@v8.1.0/pkg/edgegrid/README.md (about) 1 # edgegrid authorization library 2 3 This library provides Akamai `.edgerc` configuration parsing and `http.Request` signing. 4 5 ## EdgeGrid Configuration Files 6 7 The default location for the `.edgerc` file is `$HOME/.edgerc`. This file has a standard ini-file format. The default section is `default`. Multiple sections can be stored in the same ini-file for other configurations such as production, staging, or development. 8 9 ``` 10 [default] 11 client_secret = <default secret> 12 host = <default host> 13 access_token = <default access token> 14 client_token = <default client token> 15 16 [dev] 17 client_secret = <dev secret> 18 host = <dev host> 19 access_token = <dev access token> 20 client_token = <dev client token> 21 ``` 22 23 ## Basic Example 24 25 ``` 26 func main() { 27 edgerc := Must(New()) 28 29 client := http.Client{} 30 31 req, _ := http.NewRequest(http.MethodGet, "/papi/v1/contracts", nil) 32 33 edgerc.SignRequest(req) 34 35 resp, err := client.Do(req) 36 if err != nil { 37 log.Fataln(err) 38 } 39 40 // do something with response 41 } 42 ``` 43 44 ## Using a custom `.edgerc` file and section 45 46 ``` 47 edgerc := Must(New( 48 WithFile("/some/other/edgerc"), 49 WithSection("production"), 50 )) 51 } 52 ``` 53 54 ## Loading from environment variables 55 56 By default, it uses `AKAMAI_HOST`, `AKAMAI_CLIENT_TOKEN`, `AKAMAI_CLIENT_SECRET`, `AKAMAI_ACCESS_TOKEN`, and `AKAMAI_MAX_BODY` variables. 57 58 You can define multiple configurations by prefixing with the section name specified, e.g. passing "ccu" will cause it to look for `AKAMAI_CCU_HOST`, etc. 59 60 If `AKAMAI_{SECTION}` does not exist, it will fall back to just `AKAMAI_`. 61 62 ``` 63 // Load from AKAMA_CCU_ 64 edgerc := Must(New( 65 WithEnv(true), 66 WithSection("ccu"), 67 )) 68 } 69 ```