Add subscription, with notification
This commit is contained in:
parent
0e080dd0a2
commit
031a1ef7ce
|
|
@ -1,9 +1,13 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import "log"
|
import (
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"strings"
|
||||||
//import "strconv"
|
//import "strconv"
|
||||||
import "net/http"
|
"net/http"
|
||||||
|
"net/url"
|
||||||
|
)
|
||||||
|
|
||||||
type subscriptionHandler struct {
|
type subscriptionHandler struct {
|
||||||
}
|
}
|
||||||
|
|
@ -20,9 +24,9 @@ func (handler *subscriptionHandler) ServeHTTP(w http.ResponseWriter, r *http.Req
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// mode := r.Form.Get("hub.mode")
|
mode := r.Form.Get("hub.mode")
|
||||||
// callback := r.Form.Get("hub.callback")
|
callback := r.Form.Get("hub.callback")
|
||||||
// topic := r.Form.Get("hub.topic")
|
topic := r.Form.Get("hub.topic")
|
||||||
// leaseSecondsStr := r.Form.Get("hub.lease_seconds")
|
// leaseSecondsStr := r.Form.Get("hub.lease_seconds")
|
||||||
// leaseSeconds, err := strconv.ParseInt(leaseSecondsStr, 10, 64)
|
// leaseSeconds, err := strconv.ParseInt(leaseSecondsStr, 10, 64)
|
||||||
// if leaseSecondsStr != "" && err != nil {
|
// if leaseSecondsStr != "" && err != nil {
|
||||||
|
|
@ -30,6 +34,39 @@ func (handler *subscriptionHandler) ServeHTTP(w http.ResponseWriter, r *http.Req
|
||||||
// return
|
// return
|
||||||
// }
|
// }
|
||||||
// secret := r.Form.Get("hub.secret")
|
// secret := r.Form.Get("hub.secret")
|
||||||
|
|
||||||
|
if mode == "subscribe" {
|
||||||
|
callbackURL, err := url.Parse(callback)
|
||||||
|
if err != nil {
|
||||||
|
http.Error(w, "Can't parse url", 400)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
topicURL, err := url.Parse(topic)
|
||||||
|
if err != nil {
|
||||||
|
http.Error(w, "Can't parse url", 400)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
w.WriteHeader(202)
|
||||||
|
fmt.Fprint(w, "Accepted")
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
client := http.Client{}
|
||||||
|
req, err := http.NewRequest("POST", callbackURL.String(), strings.NewReader("TEST"))
|
||||||
|
req.Header.Add("Content-Type", "text/plain")
|
||||||
|
req.Header.Add("Link", fmt.Sprintf("<https://hub.stuifzandapp.com/>; rel=hub, <%s>; rel=self", topicURL.String()))
|
||||||
|
res, err := client.Do(req)
|
||||||
|
log.Println(res, err)
|
||||||
|
}()
|
||||||
|
|
||||||
|
return
|
||||||
|
} else if mode == "unsubcribe" {
|
||||||
|
return
|
||||||
|
} else {
|
||||||
|
http.Error(w, "Unknown hub.mode", 400)
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user