Report errors in API to #bunker

This commit is contained in:
Howl 2016-05-22 17:11:07 +02:00
parent a25512fb96
commit d5caa1fdc2
2 changed files with 21 additions and 5 deletions

View File

@ -1,6 +1,9 @@
package app
import (
"fmt"
"git.zxq.co/ripple/schiavolib"
"github.com/fatih/color"
"github.com/gin-gonic/gin"
)
@ -12,10 +15,13 @@ func ErrorHandler() gin.HandlerFunc {
errs := c.Errors.Errors()
if len(errs) != 0 {
color.Red("!!! ERRORS OCCURRED !!!")
color.Red("==> %s %s", c.Request.Method, c.Request.URL.Path)
var out string
out += fmt.Sprintf("==> %s %s\n", c.Request.Method, c.Request.URL.Path)
for _, err := range errs {
color.Red("===> %s", err)
out += fmt.Sprintf("===> %s\n", err)
}
color.Red(out)
schiavo.Bunker.Send("Errors occurred:\n```\n" + out + "```")
}
}
}

16
main.go
View File

@ -11,6 +11,7 @@ import (
"git.zxq.co/ripple/rippleapi/app"
"git.zxq.co/ripple/rippleapi/common"
"git.zxq.co/ripple/schiavolib"
"github.com/rcrowley/goagain"
// Golint pls dont break balls
_ "github.com/go-sql-driver/mysql"
@ -26,9 +27,13 @@ func main() {
if halt {
return
}
schiavo.Prefix = "Ripple API"
db, err := sql.Open(conf.DatabaseType, conf.DSN)
if err != nil {
log.Fatal(err)
schiavo.Bunker.Send(err.Error())
log.Fatalln(err)
}
engine := app.Start(conf, db)
@ -43,10 +48,11 @@ func main() {
l, err = net.Listen("tcp", conf.ListenTo)
}
if nil != err {
schiavo.Bunker.Send(err.Error())
log.Fatalln(err)
}
log.Println("LISTENINGU STARTUATO ON", l.Addr())
schiavo.Bunker.Send(fmt.Sprint("LISTENINGU STARTUATO ON", l.Addr()))
// Accept connections in a new goroutine.
go http.Serve(l, engine)
@ -54,11 +60,12 @@ func main() {
} else {
// Resume accepting connections in a new goroutine.
log.Println("LISTENINGU RESUMINGU ON", l.Addr())
schiavo.Bunker.Send(fmt.Sprint("LISTENINGU RESUMINGU ON", l.Addr()))
go http.Serve(l, engine)
// Kill the parent, now that the child has started successfully.
if err := goagain.Kill(); nil != err {
schiavo.Bunker.Send(err.Error())
log.Fatalln(err)
}
@ -66,6 +73,7 @@ func main() {
// Block the main goroutine awaiting signals.
if _, err := goagain.Wait(l); nil != err {
schiavo.Bunker.Send(err.Error())
log.Fatalln(err)
}
@ -74,9 +82,11 @@ func main() {
//
// In this case, we'll simply stop listening and wait one second.
if err := l.Close(); nil != err {
schiavo.Bunker.Send(err.Error())
log.Fatalln(err)
}
if err := db.Close(); err != nil {
schiavo.Bunker.Send(err.Error())
log.Fatalln(err)
}
time.Sleep(time.Second * 1)