/
links.go
62 lines (54 loc) · 1.48 KB
/
links.go
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package utils
import (
"encoding/json"
"io/ioutil"
)
// Link represents a single link entry
type Link struct {
Brand string `json:"brand"`
Icon string `json:"icon"`
Name string `json:"name"`
Link string `json:"link"`
Redirects []struct {
Src string `json:"src"`
Dest string `json:"dest"`
Code int `json:"code"`
} `json:"redirects"`
}
// Links represents the entire JSON structure
type Links struct {
DownloadTagVer string `json:"DOWNLOAD_TAG_VER"`
Meta Meta `json:"META"`
Bio Bio `json:"BIO"`
BaseShortURL string `json:"BASE_SHORT_URL"`
EnableRedirects bool `json:"ENABLE_REDIRECTS"`
Links []Link `json:"LINKS"`
}
// Meta represents the meta section of the JSON
type Meta struct {
Title string `json:"TITLE"`
Author string `json:"AUTHOR"`
Description string `json:"DESCRIPTION"`
IconURL string `json:"ICON_URL"`
Theme string `json:"THEME"`
}
// Bio represents the bio section of the JSON
type Bio struct {
IconURL string `json:"ICON_URL"`
Title string `json:"TITLE"`
Description string `json:"DESCRIPTION"`
Footer string `json:"FOOTER"`
}
// ParseLinksJSON parses the JSON file at the given path and returns the Links structure
func ParseLinksJSON(assetsPath string) (*Links, error) {
data, err := ioutil.ReadFile(assetsPath)
if err != nil {
return nil, err
}
var links Links
err = json.Unmarshal(data, &links)
if err != nil {
return nil, err
}
return &links, nil
}