-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathapi.go
More file actions
47 lines (37 loc) · 769 Bytes
/
api.go
File metadata and controls
47 lines (37 loc) · 769 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package main
import (
"encoding/json"
"errors"
"io"
"net/http"
)
const oscAPIUrl = "https://hbb1.oscwii.org/api/v3/contents"
type OSCApp struct {
Shop Shop `json:"shop"`
}
type Shop struct {
TitleId string `json:"title_id"`
Version int `json:"title_version"`
}
func GetOSCApp(titleId string) (*OSCApp, error) {
resp, err := http.Get(oscAPIUrl)
if err != nil {
return nil, err
}
if resp.StatusCode != http.StatusOK {
return nil, errors.New("osc API returned non OK status code")
}
data, _ := io.ReadAll(resp.Body)
defer resp.Body.Close()
var apps []OSCApp
err = json.Unmarshal(data, &apps)
if err != nil {
return nil, err
}
for _, app := range apps {
if app.Shop.TitleId == titleId {
return &app, nil
}
}
return nil, nil
}