()
| 18 | } |
| 19 | |
| 20 | func demo() { |
| 21 | resp, err := http.Get("https://api.github.com/users/ardanlabs") |
| 22 | if err != nil { |
| 23 | fmt.Println("ERROR:", err) |
| 24 | return |
| 25 | } |
| 26 | |
| 27 | if resp.StatusCode != http.StatusOK { |
| 28 | fmt.Printf("ERROR: bad status - %s\n", resp.Status) |
| 29 | return |
| 30 | } |
| 31 | |
| 32 | ctype := resp.Header.Get("Content-Type") |
| 33 | fmt.Println("content-type:", ctype) |
| 34 | |
| 35 | // io.Copy(os.Stdout, resp.Body) |
| 36 | var reply struct { |
| 37 | Name string |
| 38 | NumRepos int `json:"public_repos"` |
| 39 | } |
| 40 | dec := json.NewDecoder(resp.Body) |
| 41 | if err := dec.Decode(&reply); err != nil { |
| 42 | fmt.Println("ERROR:", err) |
| 43 | return |
| 44 | } |
| 45 | fmt.Println(reply.Name, reply.NumRepos) |
| 46 | } |
| 47 | |
| 48 | // UserInfo return name and number of public repos from GitHub API. |
| 49 | func UserInfo(ctx context.Context, login string) (string, int, error) { |
nothing calls this directly
no outgoing calls
no test coverage detected