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 {
|
func LoginHandle(c *fiber.Ctx) error {
|
||||||
var p = struct {
|
var p = struct {
|
||||||
Code string `json:"code" validate:"required"`
|
Code string `json:"code" validate:"required"`
|
||||||
Email string `json:"email" validate:"email"`
|
Email string `json:"email" label:"邮箱" validate:"email"`
|
||||||
}{}
|
}{}
|
||||||
err := Bind(c, &p)
|
err := Bind(c, &p)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -24,11 +24,16 @@ func init() {
|
||||||
panic(fmt.Errorf("uni.GetTranslator(%s) failed", "zh"))
|
panic(fmt.Errorf("uni.GetTranslator(%s) failed", "zh"))
|
||||||
}
|
}
|
||||||
Validate.RegisterTagNameFunc(func(field reflect.StructField) string {
|
Validate.RegisterTagNameFunc(func(field reflect.StructField) string {
|
||||||
label := field.Tag.Get("json")
|
addWarp := func(tag string) string {
|
||||||
if label == "" {
|
return "[" + tag + "]"
|
||||||
return field.Name
|
|
||||||
}
|
}
|
||||||
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)
|
err := zh_translations.RegisterDefaultTranslations(Validate, trans)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -41,7 +41,7 @@ func middlewareResp(c *fiber.Ctx) error {
|
||||||
type Response struct {
|
type Response struct {
|
||||||
Code int `json:"code"`
|
Code int `json:"code"`
|
||||||
Message string `json:"message"`
|
Message string `json:"message"`
|
||||||
Data json.RawMessage `json:"data"`
|
Data json.RawMessage `json:"data,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func middlewareError(ctx *fiber.Ctx, err error) error {
|
func middlewareError(ctx *fiber.Ctx, err error) error {
|
||||||
|
|
Loading…
Reference in New Issue