Refactor to make the maintanance simpler
- Fixed issue with webhooks
This commit is contained in:
+30
-9
@@ -5,6 +5,7 @@ import (
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net/http"
|
||||
"net/http/httputil"
|
||||
|
||||
"github.com/pusher/pusher-http-go"
|
||||
)
|
||||
@@ -13,10 +14,11 @@ var client pusher.Client
|
||||
|
||||
func init() {
|
||||
client = pusher.Client{
|
||||
AppId: "1",
|
||||
Key: "278d525bdf162c739803",
|
||||
Secret: "7ad3753142a6693b25b9",
|
||||
Host: ":8080",
|
||||
AppId: "1",
|
||||
Key: "278d525bdf162c739803",
|
||||
Secret: "7ad3753142a6693b25b9",
|
||||
Host: ":8080",
|
||||
Cluster: "hello",
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,7 +36,7 @@ func pusherPresenceAuth(res http.ResponseWriter, req *http.Request) {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Fprint(res, string(response))
|
||||
_, _ = fmt.Fprint(res, string(response))
|
||||
}
|
||||
|
||||
func pusherPrivateAuth(res http.ResponseWriter, req *http.Request) {
|
||||
@@ -48,19 +50,38 @@ func pusherPrivateAuth(res http.ResponseWriter, req *http.Request) {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Fprint(res, string(response))
|
||||
_, _ = fmt.Fprint(res, string(response))
|
||||
}
|
||||
|
||||
func triggerMessage(res http.ResponseWriter, _ *http.Request) {
|
||||
client.Trigger("private-messages", "messages", "The message from server")
|
||||
_, err := client.Trigger("private-messages", "messages", "The message from server")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Fprint(res, "OK")
|
||||
_, _ = fmt.Fprint(res, "OK")
|
||||
}
|
||||
|
||||
func hookcallback(res http.ResponseWriter, r *http.Request) {
|
||||
bytes, err := httputil.DumpRequest(r, true)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Println(string(bytes))
|
||||
|
||||
_, err = client.Trigger("private-webhook", "mywebhook", "The Webhoook from server")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
_, _ = fmt.Fprint(res, "OK")
|
||||
}
|
||||
|
||||
func main() {
|
||||
http.HandleFunc("/pusher/presence/auth", pusherPresenceAuth)
|
||||
http.HandleFunc("/pusher/private/auth", pusherPrivateAuth)
|
||||
http.HandleFunc("/trigger", triggerMessage)
|
||||
http.HandleFunc("/hook", hookcallback)
|
||||
http.Handle("/", http.FileServer(http.Dir("./")))
|
||||
http.ListenAndServe(":5000", nil)
|
||||
_ = http.ListenAndServe(":5000", nil)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user