Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
package main
import (
type DDresults struct {
Results struct {
Metrics []string `json:"metrics"`
} `json:"results"`
func GetUrl(myurl, prefix, apikey, appkey string) []string {
// Creating the request
req, err := http.NewRequest("GET", myurl, nil)
if err != nil {
// Adding Query strings
q := url.Values{}
// Encode the query strings
req.URL.RawQuery = q.Encode()
// Adding headers
req.Header.Add("DD-API-KEY", apikey)
req.Header.Add("DD-APPLICATION-KEY", appkey)
// To print query string
// fmt.Println(req.URL.String())
// Use default http client to make the request
res, err := http.DefaultClient.Do(req)
// Make sure we close the connection when we recieve everything
defer res.Body.Close()
// Read bode and convert to string
bodyBytes, _ := ioutil.ReadAll(res.Body)
// // Convert to string...not sure
// bodyString := string(bodyBytes)
// fmt.Println("API Response as String:\n\n\n" + bodyString)
// Decode Json body
var results DDresults
json.Unmarshal(bodyBytes, &results)
return results.Results.Metrics
//fmt.Printf("API Response as struct %+v\n", results.Results.Metrics)
func main() {
myurl := ""
prefix := "metrics:aws.ecs"
apikey := "asdfasdfasdfasdfasdfasdf45345323"
appkey := "dsfasdfsaddfasdfasdf686868686687687686876sdfasdfasdf"
results := GetUrl(myurl,prefix,apikey,appkey)
wordsToTest := []string(results)
// Choose a set of bag sizes, more is more accurate but slower
bagSizes := []int{3}
// Create a closestmatch object
cm := closestmatch.New(wordsToTest, bagSizes)
fmt.Println(cm.ClosestN("aws.ecs.service.cpuutilization.minimum", 3))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment