From d3b4e8f5e50f441b90c713d66e141d0fd13e50ea Mon Sep 17 00:00:00 2001 From: icechen Date: Thu, 13 Jan 2022 02:33:44 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0label?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/zeus/api/lark/internal/user/user.go | 2 +- app/zeus/api/lark/internal/user/validator.go | 13 +++++++++---- app/zeus/api/lark/main.go | 2 +- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/app/zeus/api/lark/internal/user/user.go b/app/zeus/api/lark/internal/user/user.go index 55b5a1e..e6f3d02 100644 --- a/app/zeus/api/lark/internal/user/user.go +++ b/app/zeus/api/lark/internal/user/user.go @@ -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 { diff --git a/app/zeus/api/lark/internal/user/validator.go b/app/zeus/api/lark/internal/user/validator.go index 785d395..2d6349e 100644 --- a/app/zeus/api/lark/internal/user/validator.go +++ b/app/zeus/api/lark/internal/user/validator.go @@ -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 { diff --git a/app/zeus/api/lark/main.go b/app/zeus/api/lark/main.go index 887e254..0d0f8a0 100755 --- a/app/zeus/api/lark/main.go +++ b/app/zeus/api/lark/main.go @@ -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 {