31 lines
520 B
Go
31 lines
520 B
Go
package api
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/json"
|
|
"net/http"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
func (s *Service) Recovery(c *gin.Context) {
|
|
defer func() {
|
|
if err := recover(); err != nil {
|
|
s.Logger.Println("[PANIC]", err)
|
|
c.JSON(http.StatusInternalServerError, gin.H{
|
|
"error": "an unexpected error occur",
|
|
})
|
|
}
|
|
}()
|
|
c.Next()
|
|
}
|
|
|
|
func (s *Service) Dump(o interface{}) {
|
|
b := bytes.NewBuffer([]byte{})
|
|
enc := json.NewEncoder(b)
|
|
enc.SetIndent("", " ")
|
|
enc.Encode(o)
|
|
|
|
s.Logger.Printf("%s", b.Bytes())
|
|
}
|