mirror of
https://github.com/packwiz/packwiz.git
synced 2025-11-19 01:24:32 +01:00
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>
This commit is contained in:
33
github/request.go
Normal file
33
github/request.go
Normal file
@@ -0,0 +1,33 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user