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

Function UserInfo

github/github.go:49–66  ·  view source on GitHub ↗

UserInfo return name and number of public repos from GitHub API.

(ctx context.Context, login string)

Source from the content-addressed store, hash-verified

47
48// UserInfo return name and number of public repos from GitHub API.
49func UserInfo(ctx context.Context, login string) (string, int, error) {
50 url := "https://api.github.com/users/" + login
51 req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
52 if err != nil {
53 return "", 0, err
54 }
55 // resp, err := http.Get("https://api.github.com/users/ardanlabs")
56 resp, err := http.DefaultClient.Do(req)
57 if err != nil {
58 return "", 0, err
59 }
60
61 if resp.StatusCode != http.StatusOK {
62 return "", 0, fmt.Errorf("%q - bad status: %s", url, resp.Status)
63 }
64
65 return parseResponse(resp.Body)
66}
67
68func parseResponse(r io.Reader) (string, int, error) {
69 var reply struct {

Callers 1

mainFunction · 0.85

Calls 1

parseResponseFunction · 0.85

Tested by

no test coverage detected