mirror of
https://github.com/packwiz/packwiz.git
synced 2025-04-19 13:06:30 +02:00
- "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>
34 lines
651 B
Go
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
|
|
}
|