Fix loading of subscriptions.json
This commit is contained in:
parent
2f9f57107d
commit
ace9f5a3df
|
@ -160,8 +160,13 @@ func (handler *subscriptionHandler) ServeHTTP(w http.ResponseWriter, r *http.Req
|
||||||
|
|
||||||
func (handler *subscriptionHandler) load() error {
|
func (handler *subscriptionHandler) load() error {
|
||||||
file, err := os.Open("./subscription.json")
|
file, err := os.Open("./subscription.json")
|
||||||
if err != nil && os.IsExist(err) {
|
if err != nil {
|
||||||
|
if os.IsExist(err) {
|
||||||
return err
|
return err
|
||||||
|
} else {
|
||||||
|
handler.Subscribers = make(map[string][]Subscriber)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
defer file.Close()
|
defer file.Close()
|
||||||
dec := json.NewDecoder(file)
|
dec := json.NewDecoder(file)
|
||||||
|
@ -183,9 +188,7 @@ func (handler *subscriptionHandler) save() error {
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
handler := &subscriptionHandler{}
|
handler := &subscriptionHandler{}
|
||||||
if err := handler.load(); err != nil {
|
handler.load()
|
||||||
handler.Subscribers = make(map[string][]Subscriber)
|
|
||||||
}
|
|
||||||
http.Handle("/", handler)
|
http.Handle("/", handler)
|
||||||
log.Fatal(http.ListenAndServe(":80", nil))
|
log.Fatal(http.ListenAndServe(":80", nil))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user