Created
July 2, 2018 21:35
-
-
Save Cibernomadas/72f1c25f2c3203e6e5e5515dab43503f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func RegisterRecovery() gin.HandlerFunc { | |
return func(c *gin.Context) { | |
defer func() { | |
if err := recover(); err != nil { | |
httprequest, _ := httputil.DumpRequest(c.Request, false) | |
m := gomail.NewMessage() | |
m.SetHeader("From", "goblog@cibernomadas.es") | |
m.SetHeader("To", "admin@cibernomadas.es") | |
m.SetHeader("Subject", "GoBlog Error") | |
m.SetBody("text/plain", string(httprequest)) | |
d := gomail.Dialer{Host: "localhost", Port: 25} | |
if err := d.DialAndSend(m); err != nil { | |
panic(err) | |
} | |
c.HTML(http.StatusOK, "index", gin.H{ | |
"title": "Hi! GoBlog.", | |
"error": "You found an error. The administrator has been notified.", | |
}) | |
} | |
}() | |
c.Next() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment