MCPcopy Create free account
hub / github.com/ardanlabs/practical-go / demo

Function demo

github/github.go:20–46  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

18}
19
20func 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.
49func UserInfo(ctx context.Context, login string) (string, int, error) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected