| 23 | var buildNumberRegex = regexp.MustCompile(`"BUILD_NUMBER":\s*"(\d+)"`) |
| 24 | |
| 25 | func fetchBuildNumber() (string, error) { |
| 26 | resp, err := http.Get(api.BaseEndpoint + "/login") |
| 27 | if err != nil { |
| 28 | return "", err |
| 29 | } |
| 30 | defer resp.Body.Close() |
| 31 | |
| 32 | if resp.StatusCode < http.StatusOK || resp.StatusCode >= http.StatusMultipleChoices { |
| 33 | return "", fmt.Errorf("failed to fetch login page; status=%q", resp.Status) |
| 34 | } |
| 35 | |
| 36 | body, err := io.ReadAll(resp.Body) |
| 37 | if err != nil { |
| 38 | return "", err |
| 39 | } |
| 40 | |
| 41 | matches := buildNumberRegex.FindSubmatch(body) |
| 42 | if len(matches) < 2 { |
| 43 | return "", fmt.Errorf("failed to find build number; matches=%v", matches) |
| 44 | } |
| 45 | return string(matches[1]), nil |
| 46 | } |
| 47 | |
| 48 | func main() { |
| 49 | out := flag.String("out", "generated.go", "out filename") |