Skip to content

Commit

Permalink
fix(error): format error messageˆ
Browse files Browse the repository at this point in the history
  • Loading branch information
LinkinStars committed Aug 14, 2023
1 parent 66a04d0 commit a8ec3ec
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion internal/base/validator/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"reflect"
"strings"
"unicode"

"github.com/answerdev/answer/internal/base/reason"
"github.com/answerdev/answer/internal/base/translator"
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit a8ec3ec

Please sign in to comment.