Merge remote-tracking branch 'origin/feat/1.1.2/errmsg' into test

This commit is contained in:
LinkinStars 2023-08-14 18:44:32 +08:00
commit a9e5e1e4ec
1 changed files with 7 additions and 1 deletions

View File

@ -5,6 +5,7 @@ import (
"fmt" "fmt"
"reflect" "reflect"
"strings" "strings"
"unicode"
"github.com/answerdev/answer/internal/base/reason" "github.com/answerdev/answer/internal/base/reason"
"github.com/answerdev/answer/internal/base/translator" "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 { if len(field.ErrorField) == 0 {
continue 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, ".") { if !strings.HasSuffix(field.ErrorMsg, ".") {
field.ErrorMsg += "." field.ErrorMsg += "."
} }
field.ErrorMsg = fmt.Sprintf("%s%s", strings.ToUpper(string(field.ErrorMsg[0])), field.ErrorMsg[1:])
} }
}() }()
err = m.Validate.Struct(value) err = m.Validate.Struct(value)