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:
unilock
2023-05-30 21:01:29 -04:00
parent 837b4db760
commit 6116393310
4 changed files with 112 additions and 169 deletions

33
github/request.go Normal file
View 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
}