This commit is contained in:
Peter Stuifzand 2018-12-10 19:34:30 +01:00
commit 309b034180
2 changed files with 15 additions and 19 deletions

View File

@ -2,8 +2,8 @@ pipeline:
build:
image: golang
commands:
- go get github.com/pstuifzand/websub-hub/cmd/hubserver
- go build github.com/pstuifzand/websub-hub/cmd/hubserver
- go get p83.nl/go/websub-hub/cmd/hubserver
- go build p83.nl/go/websub-hub/cmd/hubserver
publish:
image: plugins/docker

View File

@ -70,12 +70,12 @@ func (handler *subscriptionHandler) handlePublish(w http.ResponseWriter, r *http
return err
}
handler.incStat(fmt.Sprintf("publish.%s", topic))
// handler.incStat(fmt.Sprintf("publish.%s", topic))
if subs, e := handler.Subscribers[topic]; e {
for _, sub := range subs {
handler.incStat(fmt.Sprintf("publish.post.%s.%s", topic, sub.Callback))
// handler.incStat(fmt.Sprintf("publish.post.%s.%s", topic, sub.Callback))
log.Printf("publish: creating post to %s\n", sub.Callback)
postReq, err := http.NewRequest("POST", sub.Callback, strings.NewReader(string(feedContent)))
if err != nil {
@ -257,23 +257,23 @@ func (handler *subscriptionHandler) addSubscriberCallback(topic string, subscrib
}
func (handler *subscriptionHandler) incStat(name string) {
if v, e := handler.Stats[name]; e {
handler.Stats[name] = Stat{LastUpdate: time.Now(), Updates: v.Updates + 1}
} else {
handler.Stats[name] = Stat{LastUpdate: time.Now(), Updates: 1}
}
handler.saveStats()
// if v, e := handler.Stats[name]; e {
// handler.Stats[name] = Stat{LastUpdate: time.Now(), Updates: v.Updates + 1}
// } else {
// handler.Stats[name] = Stat{LastUpdate: time.Now(), Updates: 1}
// }
// handler.saveStats()
}
func (handler *subscriptionHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if r.Method == http.MethodGet {
fmt.Fprintln(w, "WebSub hub")
if r.URL.Query().Get("debug") == "1" {
handler.incStat("http.index.debug")
// handler.incStat("http.index.debug")
enc := json.NewEncoder(w)
enc.SetIndent("", " ")
enc.Encode(handler.Subscribers)
enc.Encode(handler.Stats)
//enc.Encode(handler.Stats)
}
return
}
@ -310,9 +310,7 @@ func (handler *subscriptionHandler) ServeHTTP(w http.ResponseWriter, r *http.Req
func (handler *subscriptionHandler) loadStats() error {
file, err := os.Open("./stats.json")
if err != nil {
if os.IsExist(err) {
return err
} else {
if os.IsNotExist(err) {
handler.Stats = make(map[string]Stat)
return nil
}
@ -329,9 +327,7 @@ func (handler *subscriptionHandler) loadSubscriptions() error {
file, err := os.Open("./subscription.json")
if err != nil {
if os.IsExist(err) {
return err
} else {
if os.IsNotExist(err) {
handler.Subscribers = make(map[string][]Subscriber)
return nil
}
@ -347,7 +343,7 @@ func (handler *subscriptionHandler) load() error {
if err != nil {
return err
}
return handler.loadStats()
return nil //handler.loadStats()
}
func (handler *subscriptionHandler) saveStats() error {