Skip to content

govalidStruct validation that just works.

Composable, i18n-ready, panic-safe — declared with struct tags, extended with your own checkers.

govalid

A familiar Go API

go
package main

import (
    "fmt"

    "github.com/wuhan005/govalid"
)

func main() {
    v := struct {
        Name string `valid:"required;username" label:"昵称"`
        ID   int    `valid:"required;min:0;max:999" label:"用户编号"`
        Mail string `valid:"required;email"     label:"邮箱"`
    }{
        Name: "e99_",
        ID:   1990,
        Mail: "i@github.red.",
    }

    if errs, ok := govalid.Check(v); !ok {
        for _, err := range errs {
            fmt.Println(err)
        }
    }
}
text
昵称的最后一个字符不能为下划线
用户编号应小于999
邮箱不是合法的电子邮箱格式

Why govalid?

govalidBring-your-own if
Where rules liveBeside the field, in struct tagsScattered across handlers
Cross-field rulesequal: checker + Validate()Manual conditionals
Localized messagesBuilt-in i18n + SetMessageTemplatesDIY
Custom rulesCheckers["myRule"] = …Copy-paste functions
Safety on weird inputsnil/map/embedded/unexported handledUp to you

Released under the MIT License.