MCPcopy
hub / github.com/ayn2op/discordo / fetchBuildNumber

Function fetchBuildNumber

internal/http/generator.go:25–46  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

23var buildNumberRegex = regexp.MustCompile(`"BUILD_NUMBER":\s*"(\d+)"`)
24
25func 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
48func main() {
49 out := flag.String("out", "generated.go", "out filename")

Callers 1

mainFunction · 0.85

Calls 1

GetMethod · 0.80

Tested by

no test coverage detected