shutdown gracefully

This commit is contained in:
0xJacky 2022-02-18 12:08:16 +08:00
parent 08d3fbe0ff
commit 03de36ff2e
5 changed files with 46 additions and 46 deletions

View file

@ -1,8 +1,6 @@
package api
import (
"bytes"
"encoding/json"
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin/binding"
"github.com/go-playground/locales/zh"
@ -12,30 +10,8 @@ import (
"log"
"net/http"
"reflect"
"regexp"
)
type JsonSnakeCase struct {
Value interface{}
}
func (c JsonSnakeCase) MarshalJSON() ([]byte, error) {
// Regexp definitions
var keyMatchRegex = regexp.MustCompile(`\"(\w+)\":`)
var wordBarrierRegex = regexp.MustCompile(`(\w)([A-Z])`)
marshalled, err := json.Marshal(c.Value)
converted := keyMatchRegex.ReplaceAllFunc(
marshalled,
func(match []byte) []byte {
return bytes.ToLower(wordBarrierRegex.ReplaceAll(
match,
[]byte(`${1}_${2}`),
))
},
)
return converted, err
}
func ErrHandler(c *gin.Context, err error) {
log.Println(err)
c.JSON(http.StatusInternalServerError, gin.H{