UserInfo return name and number of public repos from GitHub API.
(ctx context.Context, login string)
| 47 | |
| 48 | // UserInfo return name and number of public repos from GitHub API. |
| 49 | func 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 | |
| 68 | func parseResponse(r io.Reader) (string, int, error) { |
| 69 | var reply struct { |