-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
public.go
51 lines (43 loc) · 1.26 KB
/
public.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
package git
import (
"encoding/json"
"io/ioutil"
"net/http"
)
// PublicList represents a curated list of public package entries.
type PublicList struct {
Name string `json:"name"`
Author string `json:"author"`
Description string `json:"description"`
Entries []PublicEntry `json:"entries"`
}
// PublicEntry represents an entry in the public package repository by some Author.
// One entry can contain multiple git repos where packages for S&D are stored.
type PublicEntry struct {
Author string `json:"author"`
Contact string `json:"contact"`
Repos []RepoEntry `json:"repos"`
}
// RepoEntry represents a single git repository with packages for S&D.
type RepoEntry struct {
Name string `json:"name"`
Description string `json:"description"`
URL string `json:"url"`
}
// GetPackages fetches a PublicList by URL. It expects a JSON encoded file.
func GetPackages(url string) (PublicList, error) {
res, err := http.Get(url)
if err != nil {
return PublicList{}, err
}
defer res.Body.Close()
bytes, err := ioutil.ReadAll(res.Body)
if err != nil {
return PublicList{}, err
}
var public PublicList
if err := json.Unmarshal(bytes, &public); err != nil {
return PublicList{}, err
}
return public, nil
}