mirror of
https://github.com/0xJacky/nginx-ui.git
synced 2025-05-11 02:15:48 +02:00
shutdown gracefully
This commit is contained in:
parent
08d3fbe0ff
commit
03de36ff2e
5 changed files with 46 additions and 46 deletions
24
api/api.go
24
api/api.go
|
@ -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{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue