tpphu / golang-training

Golang for Backend Developer with Nordic Coder
https://nordiccoder.com/khoa-hoc/golang-for-backend-dev/
131 stars 50 forks source link

Localize báo lỗi thân thiện hơn dành cho tiếng Việt và tiếng Anh #18

Closed tpphu closed 5 years ago

tpphu commented 5 years ago

Các bạn hãy tiếp tục làm bài tập số 3 với suy nghĩ xem làm thế nào để báo lỗi thân thiện hơn và theo ngôn ngữ: en, vi

hiepndd commented 5 years ago

Da anh @tpphu , em co custom lai error theo ngon ngu en

func translateIndividual(trans ut.Translator) string {
    type Note struct {
        Title string `validate:"min=6,max=100"`
    }
    var note Note
    err := validate.Struct(note)
    if err != nil {
        errs := err.(validator.ValidationErrors)
        for _, e := range errs {
            return e.Translate(trans)
        }
    }
    return ""
}