MCPcopy Create free account
hub / github.com/SamNet-dev/snix / resolveLatest

Function resolveLatest

cmd/snix/update.go:123–146  ·  view source on GitHub ↗

resolveLatest follows the /releases/latest redirect to learn the tag without needing the GitHub API (which is rate-limited for unauth users).

()

Source from the content-addressed store, hash-verified

121// resolveLatest follows the /releases/latest redirect to learn the tag
122// without needing the GitHub API (which is rate-limited for unauth users).
123func resolveLatest() (string, error) {
124 client := &http.Client{
125 Timeout: 10 * time.Second,
126 CheckRedirect: func(r *http.Request, via []*http.Request) error {
127 return http.ErrUseLastResponse
128 },
129 }
130 resp, err := client.Get("https://github.com/SamNet-dev/snix/releases/latest")
131 if err != nil {
132 return "", err
133 }
134 defer resp.Body.Close()
135 loc := resp.Header.Get("Location")
136 if loc == "" {
137 // Some proxies strip redirects; fall back to the JSON API.
138 return resolveLatestAPI()
139 }
140 // Expect: https://github.com/SamNet-dev/snix/releases/tag/v0.5.0
141 idx := strings.LastIndex(loc, "/v")
142 if idx < 0 {
143 return "", fmt.Errorf("unexpected redirect: %s", loc)
144 }
145 return loc[idx+2:], nil
146}
147
148func resolveLatestAPI() (string, error) {
149 resp, err := http.Get("https://api.github.com/repos/SamNet-dev/snix/releases/latest")

Callers 1

newUpdateCmdFunction · 0.85

Calls 3

resolveLatestAPIFunction · 0.85
GetMethod · 0.80
CloseMethod · 0.65

Tested by

no test coverage detected