From a8ec3ec04542534ae7813faa667b534a0b9b8dff Mon Sep 17 00:00:00 2001 From: LinkinStars Date: Mon, 14 Aug 2023 18:43:24 +0800 Subject: [PATCH] =?UTF-8?q?fix(error):=20format=20error=20message=CB=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/base/validator/validator.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/internal/base/validator/validator.go b/internal/base/validator/validator.go index fca78e27..1853d65b 100644 --- a/internal/base/validator/validator.go +++ b/internal/base/validator/validator.go @@ -5,6 +5,7 @@ import ( "fmt" "reflect" "strings" + "unicode" "github.com/answerdev/answer/internal/base/reason" "github.com/answerdev/answer/internal/base/translator" @@ -176,10 +177,15 @@ func (m *MyValidator) Check(value interface{}) (errFields []*FormErrorField, err if len(field.ErrorField) == 0 { continue } + firstRune := []rune(field.ErrorMsg)[0] + if !unicode.IsLetter(firstRune) || !unicode.Is(unicode.Latin, firstRune) { + continue + } + upperFirstRune := unicode.ToUpper(firstRune) + field.ErrorMsg = string(upperFirstRune) + field.ErrorMsg[1:] if !strings.HasSuffix(field.ErrorMsg, ".") { field.ErrorMsg += "." } - field.ErrorMsg = fmt.Sprintf("%s%s", strings.ToUpper(string(field.ErrorMsg[0])), field.ErrorMsg[1:]) } }() err = m.Validate.Struct(value)