github.com/akamai/AkamaiOPEN-edgegrid-golang/v2@v2.17.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 if err := edgerc.Sign(r); err != nil { 34 log.Fatalln(err) 35 } 36 37 resp, err := client.Do(req) 38 if err != nil { 39 log.Fataln(err) 40 } 41 42 // do something with response 43 } 44 ``` 45 46 ## Using a custom `.edgerc` file and section 47 48 ``` 49 edgerc := Must(New( 50 WithFile("/some/other/edgerc"), 51 WithSection("production"), 52 )) 53 } 54 ``` 55 56 ## Loading from environment variables 57 58 By default, it uses `AKAMAI_HOST`, `AKAMAI_CLIENT_TOKEN`, `AKAMAI_CLIENT_SECRET`, `AKAMAI_ACCESS_TOKEN`, and `AKAMAI_MAX_BODY` variables. 59 60 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. 61 62 If `AKAMAI_{SECTION}` does not exist, it will fall back to just `AKAMAI_`. 63 64 ``` 65 // Load from AKAMA_CCU_ 66 edgerc := Must(New( 67 WithEnv(true), 68 WithSection("ccu"), 69 )) 70 } 71 ```