Report errors in API to #bunker
This commit is contained in:
parent
a25512fb96
commit
d5caa1fdc2
|
@ -1,6 +1,9 @@
|
||||||
package app
|
package app
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"git.zxq.co/ripple/schiavolib"
|
||||||
"github.com/fatih/color"
|
"github.com/fatih/color"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
@ -12,10 +15,13 @@ func ErrorHandler() gin.HandlerFunc {
|
||||||
errs := c.Errors.Errors()
|
errs := c.Errors.Errors()
|
||||||
if len(errs) != 0 {
|
if len(errs) != 0 {
|
||||||
color.Red("!!! ERRORS OCCURRED !!!")
|
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 {
|
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
16
main.go
|
@ -11,6 +11,7 @@ import (
|
||||||
|
|
||||||
"git.zxq.co/ripple/rippleapi/app"
|
"git.zxq.co/ripple/rippleapi/app"
|
||||||
"git.zxq.co/ripple/rippleapi/common"
|
"git.zxq.co/ripple/rippleapi/common"
|
||||||
|
"git.zxq.co/ripple/schiavolib"
|
||||||
"github.com/rcrowley/goagain"
|
"github.com/rcrowley/goagain"
|
||||||
// Golint pls dont break balls
|
// Golint pls dont break balls
|
||||||
_ "github.com/go-sql-driver/mysql"
|
_ "github.com/go-sql-driver/mysql"
|
||||||
|
@ -26,9 +27,13 @@ func main() {
|
||||||
if halt {
|
if halt {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
schiavo.Prefix = "Ripple API"
|
||||||
|
|
||||||
db, err := sql.Open(conf.DatabaseType, conf.DSN)
|
db, err := sql.Open(conf.DatabaseType, conf.DSN)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
schiavo.Bunker.Send(err.Error())
|
||||||
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
engine := app.Start(conf, db)
|
engine := app.Start(conf, db)
|
||||||
|
|
||||||
|
@ -43,10 +48,11 @@ func main() {
|
||||||
l, err = net.Listen("tcp", conf.ListenTo)
|
l, err = net.Listen("tcp", conf.ListenTo)
|
||||||
}
|
}
|
||||||
if nil != err {
|
if nil != err {
|
||||||
|
schiavo.Bunker.Send(err.Error())
|
||||||
log.Fatalln(err)
|
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.
|
// Accept connections in a new goroutine.
|
||||||
go http.Serve(l, engine)
|
go http.Serve(l, engine)
|
||||||
|
@ -54,11 +60,12 @@ func main() {
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
// Resume accepting connections in a new goroutine.
|
// 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)
|
go http.Serve(l, engine)
|
||||||
|
|
||||||
// Kill the parent, now that the child has started successfully.
|
// Kill the parent, now that the child has started successfully.
|
||||||
if err := goagain.Kill(); nil != err {
|
if err := goagain.Kill(); nil != err {
|
||||||
|
schiavo.Bunker.Send(err.Error())
|
||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,6 +73,7 @@ func main() {
|
||||||
|
|
||||||
// Block the main goroutine awaiting signals.
|
// Block the main goroutine awaiting signals.
|
||||||
if _, err := goagain.Wait(l); nil != err {
|
if _, err := goagain.Wait(l); nil != err {
|
||||||
|
schiavo.Bunker.Send(err.Error())
|
||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,9 +82,11 @@ func main() {
|
||||||
//
|
//
|
||||||
// In this case, we'll simply stop listening and wait one second.
|
// In this case, we'll simply stop listening and wait one second.
|
||||||
if err := l.Close(); nil != err {
|
if err := l.Close(); nil != err {
|
||||||
|
schiavo.Bunker.Send(err.Error())
|
||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
if err := db.Close(); err != nil {
|
if err := db.Close(); err != nil {
|
||||||
|
schiavo.Bunker.Send(err.Error())
|
||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
time.Sleep(time.Second * 1)
|
time.Sleep(time.Second * 1)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user