mirror of
https://github.com/idanoo/go-mastodon-matrix-webhooks.git
synced 2024-11-22 16:35:17 +00:00
Err handling
This commit is contained in:
parent
38fa1f01ff
commit
1eb5d23762
Binary file not shown.
Binary file not shown.
19
main.go
19
main.go
@ -1,6 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
@ -70,7 +71,11 @@ func handler(w http.ResponseWriter, r *http.Request) {
|
|||||||
log.Println(err.Error())
|
log.Println(err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
go sendWebhook("New report!")
|
err = sendWebhook("New report!")
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
} else if i.Event == "account.created" {
|
} else if i.Event == "account.created" {
|
||||||
var account MastodonSignUpEvent
|
var account MastodonSignUpEvent
|
||||||
err := json.NewDecoder(r.Body).Decode(&account)
|
err := json.NewDecoder(r.Body).Decode(&account)
|
||||||
@ -79,7 +84,11 @@ func handler(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
country := ipLookup(account.Object.IP)
|
country := ipLookup(account.Object.IP)
|
||||||
go sendWebhook(fmt.Sprintf("*New Signup* %s has joined from %s", account.Object.Username, country))
|
err = sendWebhook(fmt.Sprintf("*New Signup* %s has joined from %s", account.Object.Username, country))
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -96,7 +105,11 @@ func sendWebhook(msgText string) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
req, err := http.NewRequest("POST", MATRIX_WEBHOOK_URL+"/"+MATRIX_CHANNEL, b)
|
req, err := http.NewRequest("POST", MATRIX_WEBHOOK_URL+"/"+MATRIX_CHANNEL, bytes.NewBuffer(b))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
req.Header.Set("X-Custom-Header", "myvalue")
|
req.Header.Set("X-Custom-Header", "myvalue")
|
||||||
req.Header.Set("Content-Type", "application/json")
|
req.Header.Set("Content-Type", "application/json")
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user