packwiz/github/request.go
unilock 6116393310 github: fixes and improvements
- "file" -> "asset"
- "version" -> "tag" or "release" (where appropriate)
- fix updater.go for upstream changes
- make printed log messages more similar to those of other modules
- move http request function(s) to separate file "request.go"
- remove the concept of a "Mod"; we're using "Repo"s (GitHub repositories) instead
- remove unnecessary fields in structs
- use sha256 instead of sha1 for asset checksums

Signed-off-by: unilock <unilock@fennet.rentals>
2024-04-15 14:48:57 -04:00

34 lines
651 B
Go

package github
import (
"fmt"
"net/http"
)
const ghApiServer = "api.github.com"
type ghApiClient struct {
httpClient *http.Client
}
var ghDefaultClient = ghApiClient{&http.Client{}}
func (c *ghApiClient) makeGet(slug string) (*http.Response, error) {
req, err := http.NewRequest("GET", "https://" + ghApiServer + "/repos/" + slug + "/releases", nil)
if err != nil {
return nil, err
}
req.Header.Set("Accept", "application/vnd.github+json")
resp, err := c.httpClient.Do(req)
if err != nil {
return nil, err
}
if resp.StatusCode != 200 {
return nil, fmt.Errorf("invalid response status: %v", resp.Status)
}
return resp, nil
}