Skip to content

Instantly share code, notes, and snippets.

@NanXiao
Created September 7, 2016 07:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NanXiao/ad2d542e903fba638e018dc0ee4cb380 to your computer and use it in GitHub Desktop.
Save NanXiao/ad2d542e903fba638e018dc0ee4cb380 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"net/http"
"encoding/json"
)
func main() {
req, _ := http.NewRequest("GET", "https://api.clever.com/v1.1/sections", nil)
req.Header.Set("Authorization", "Bearer DEMO_TOKEN")
client := http.Client{}
resp, _ := client.Do(req)
defer resp.Body.Close()
var f interface{}
if err := json.NewDecoder(resp.Body).Decode(&f); err != nil {
fmt.Println(err)
return
}
n := f.(map[string]interface{})["data"].([]interface{})
total := 0
for _, v := range n {
total += len(v.(map[string]interface{})["data"].(map[string]interface{})["students"].([]interface{}))
}
fmt.Println(float32(total)/float32(len(n)))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment