-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsources.go
More file actions
39 lines (31 loc) · 738 Bytes
/
sources.go
File metadata and controls
39 lines (31 loc) · 738 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
package icyproxy
import (
"encoding/json"
"fmt"
"io"
"os"
)
type Source struct {
URL string `json:"url"`
MetadataJsonURL string `json:"metadataJsonUrl"`
MetadataFormat string `json:"metadataFormat"`
}
func ParseSources(r io.Reader) (map[string]Source, error) {
res := map[string]Source{}
if err := json.NewDecoder(r).Decode(&res); err != nil {
return nil, err
}
return res, nil
}
func ParseSourcesFromFile(filename string) (map[string]Source, error) {
fd, err := os.Open(filename)
if err != nil {
return nil, fmt.Errorf("error opening file: %w", err)
}
defer fd.Close()
res, err := ParseSources(fd)
if err != nil {
return nil, fmt.Errorf("error parsing sources: %w", err)
}
return res, nil
}