-
Notifications
You must be signed in to change notification settings - Fork 1
/
config_feeds.go
57 lines (38 loc) · 941 Bytes
/
config_feeds.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
package main
import "encoding/json"
import "os"
import "errors"
type FeedSchema struct {
Title string
Url string
Description string
Index struct {
ArticleLinks string
LinksPrefix string
NextLink string
}
Article struct {
Title string
Date string
DateFormat string
Content string
}
}
//readConfig will create and parse the given feeds config schema
//and return the corresponding FeedSchema array
func readFeedsConfig(file_name string) (*[]FeedSchema, error) {
//Open the config file
config_file, err := os.Open(file_name)
if err != nil {
return nil, errors.New("Could not open feeds schema file: " + err.Error())
}
//Parse the config file
config := []FeedSchema{}
jsonParser := json.NewDecoder(config_file)
err = jsonParser.Decode(&config)
if err != nil {
return nil, errors.New("Could not parse feeds schema file: " + err.Error())
} else {
return &config, nil
}
}