style: use goimport

pull/351/head
textworld 1 year ago
parent 6d3f54ecee
commit 8e6de2e20f

@ -2,6 +2,10 @@ package wp
import (
"encoding/json"
"strconv"
"strings"
"time"
"github.com/gin-gonic/gin"
sonicconst "github.com/go-sonic/sonic/consts"
"github.com/go-sonic/sonic/log"
@ -11,9 +15,6 @@ import (
"github.com/go-sonic/sonic/service"
"github.com/go-sonic/sonic/util"
"github.com/go-sonic/sonic/util/xerr"
"strconv"
"strings"
"time"
)
type PostHandler struct {
@ -29,7 +30,7 @@ func NewPostHandler(postService service.PostService) *PostHandler {
func (handler *PostHandler) List(ctx *gin.Context) (interface{}, error) {
var wpPostQuery param.WpPostQuery
if err := ctx.ShouldBind(&wpPostQuery); err != nil {
return nil, util.WrapJsonBindErr(err)
return nil, util.WrapJSONBindErr(err)
}
var postQuery param.PostQuery
@ -51,7 +52,7 @@ func (handler *PostHandler) List(ctx *gin.Context) (interface{}, error) {
func (handler *PostHandler) Create(ctx *gin.Context) (interface{}, error) {
postParam, err := parsePostParam(ctx)
if err != nil {
return nil, util.WrapJsonBindErr(err)
return nil, util.WrapJSONBindErr(err)
}
create, err := handler.PostService.Create(ctx, postParam)
@ -64,7 +65,7 @@ func (handler *PostHandler) Create(ctx *gin.Context) (interface{}, error) {
func (handler *PostHandler) Update(ctx *gin.Context) (interface{}, error) {
postParam, err := parsePostParam(ctx)
if err != nil {
return nil, util.WrapJsonBindErr(err)
return nil, util.WrapJSONBindErr(err)
}
postIDStr := ctx.Param("postID")
@ -104,7 +105,7 @@ func parsePostParam(ctx *gin.Context) (*param.Post, error) {
var wpPost param.WpPost
err := ctx.ShouldBindJSON(&wpPost)
if err != nil {
return nil, util.WrapJsonBindErr(err)
return nil, util.WrapJSONBindErr(err)
}
bytes, err := json.Marshal(wpPost)

@ -2,12 +2,13 @@ package impl
import (
"context"
"strings"
"time"
"github.com/go-sonic/sonic/model/dto"
"github.com/go-sonic/sonic/model/entity"
"github.com/go-sonic/sonic/util"
"github.com/go-sonic/sonic/util/xerr"
"strings"
"time"
"github.com/go-sonic/sonic/dal"
"github.com/go-sonic/sonic/model/param"

@ -2,12 +2,13 @@ package util
import (
"errors"
"github.com/go-playground/validator/v10"
"github.com/go-sonic/sonic/handler/trans"
"github.com/go-sonic/sonic/util/xerr"
"regexp"
"strings"
"unicode/utf8"
"github.com/go-playground/validator/v10"
"github.com/go-sonic/sonic/handler/trans"
"github.com/go-sonic/sonic/util/xerr"
)
func IfElse(condition bool, a, b interface{}) interface{} {
@ -50,7 +51,7 @@ func HTMLFormatWordCount(html string) int64 {
return int64(utf8.RuneCountInString(text) - len(blankRegexp.FindSubmatchIndex(StringToBytes(text))))
}
func WrapJsonBindErr(err error) error {
func WrapJSONBindErr(err error) error {
e := validator.ValidationErrors{}
if errors.As(err, &e) {
return xerr.WithStatus(e, xerr.StatusBadRequest).WithMsg(trans.Translate(e))

Loading…
Cancel
Save