| 213 | } |
| 214 | |
| 215 | func verifyToken(token string) error { |
| 216 | req, err := http.NewRequest("GET", "https://api.github.com/installation/repositories?per_page=1", nil) |
| 217 | if err != nil { |
| 218 | return err |
| 219 | } |
| 220 | req.Header.Set("Authorization", "Bearer "+token) |
| 221 | req.Header.Set("Accept", "application/vnd.github+json") |
| 222 | |
| 223 | resp, err := http.DefaultClient.Do(req) |
| 224 | if err != nil { |
| 225 | return err |
| 226 | } |
| 227 | defer resp.Body.Close() |
| 228 | |
| 229 | if resp.StatusCode != 200 { |
| 230 | body, _ := io.ReadAll(resp.Body) |
| 231 | return fmt.Errorf("HTTP %d: %s", resp.StatusCode, string(body)) |
| 232 | } |
| 233 | fmt.Printf(" HTTP 200 OK (X-RateLimit-Remaining: %s)\n", resp.Header.Get("X-RateLimit-Remaining")) |
| 234 | return nil |
| 235 | } |
| 236 | |
| 237 | func fatal(format string, args ...interface{}) { |
| 238 | fmt.Fprintf(os.Stderr, "FATAL: "+format+"\n", args...) |