1

Problem is how to add Webhook in the router.go Beego

// WebhookHandler ...
func (c *AuthController) WebhookHandler(w http.ResponseWriter, r *http.Request) {

publicKeyBytes, err := ioutil.ReadFile("***")
if err != nil {
    panic(err)
}

block, _ := pem.Decode(publicKeyBytes)
publicKey, err := x509.ParsePKIXPublicKey(block.Bytes)
if err != nil {
    panic(err)
}

key := publicKey.(*rsa.PublicKey)

body, err := ioutil.ReadAll(r.Body)
if err != nil {
    return
}

event, ok := VerifySignature(key, body)
if !ok {
    return
}

fmt.Println(event)
}

It works on raw GoLang

http.HandleFunc("/webhook", func(w http.ResponseWriter, r *http.Request) {
     ***
})

I tried this

beego.Router("/webhook", &controllers.AuthController{}, "*:WebhookHandler")

But how to pass request body to controller

Elliot
  • 598
  • 6
  • 25

0 Answers0