move downloader into own package
This commit is contained in:
51
pkg/epoch/manifest.go
Normal file
51
pkg/epoch/manifest.go
Normal file
@ -0,0 +1,51 @@
|
||||
package epoch
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
const (
|
||||
manifestUrl = "https://updater.project-epoch.net/api/v2/manifest"
|
||||
)
|
||||
|
||||
type File struct {
|
||||
Path string `json:"Path"`
|
||||
Hash string `json:"Hash"`
|
||||
Size int `json:"Size"`
|
||||
Custom bool `json:"Custom"`
|
||||
Urls struct {
|
||||
Digitalocean string `json:"digitalocean"`
|
||||
Cloudflare string `json:"cloudflare"`
|
||||
None string `json:"none"`
|
||||
} `json:"Urls"`
|
||||
}
|
||||
|
||||
type Manifest struct {
|
||||
Version string `json:"Version"`
|
||||
UID string `json:"Uid"`
|
||||
Files []File `json:"Files"`
|
||||
CheckedAt string `json:"checked_at"`
|
||||
}
|
||||
|
||||
func GetManifest() (*Manifest, error) {
|
||||
resp, err := http.Get(manifestUrl)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
data, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var manifest Manifest
|
||||
err = json.Unmarshal(data, &manifest)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &manifest, nil
|
||||
}
|
Reference in New Issue
Block a user