generated from pkg/go-template
feat: 增加label
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
372d70969b
commit
d3b4e8f5e5
|
@ -11,7 +11,7 @@ import (
|
|||
func LoginHandle(c *fiber.Ctx) error {
|
||||
var p = struct {
|
||||
Code string `json:"code" validate:"required"`
|
||||
Email string `json:"email" validate:"email"`
|
||||
Email string `json:"email" label:"邮箱" validate:"email"`
|
||||
}{}
|
||||
err := Bind(c, &p)
|
||||
if err != nil {
|
||||
|
|
|
@ -24,11 +24,16 @@ func init() {
|
|||
panic(fmt.Errorf("uni.GetTranslator(%s) failed", "zh"))
|
||||
}
|
||||
Validate.RegisterTagNameFunc(func(field reflect.StructField) string {
|
||||
label := field.Tag.Get("json")
|
||||
if label == "" {
|
||||
return field.Name
|
||||
addWarp := func(tag string) string {
|
||||
return "[" + tag + "]"
|
||||
}
|
||||
return label
|
||||
if labelTag := field.Tag.Get("label"); labelTag != "" {
|
||||
return addWarp(labelTag)
|
||||
}
|
||||
if jsonTag := field.Tag.Get("json"); jsonTag != "" {
|
||||
return addWarp(jsonTag)
|
||||
}
|
||||
return addWarp(field.Name)
|
||||
})
|
||||
err := zh_translations.RegisterDefaultTranslations(Validate, trans)
|
||||
if err != nil {
|
||||
|
|
|
@ -41,7 +41,7 @@ func middlewareResp(c *fiber.Ctx) error {
|
|||
type Response struct {
|
||||
Code int `json:"code"`
|
||||
Message string `json:"message"`
|
||||
Data json.RawMessage `json:"data"`
|
||||
Data json.RawMessage `json:"data,omitempty"`
|
||||
}
|
||||
|
||||
func middlewareError(ctx *fiber.Ctx, err error) error {
|
||||
|
|
Loading…
Reference in New Issue