go helper for your go application needs
go get github.com/andrietri/go-helper
import "github.com/andrietri/go-helper"
// struct
type Request struct {
Email string `json:"email" example:"andrietrilaksono@gmail.com" validate:"required" msg:"error_invalid_email"`
Name string `json:"name" example:"andrie" validate:"required" msg:"error_invalid_name"`
}
var RequestErrorMessage = map[string]string{
"error_invalid_email": "email is required",
"error_invalid_name": "name is required",
}
func main() {
var (
request Request
)
errorMessage := helper.ValidateStruct(request, RequestErrorMessage)
a, _ := json.MarshalIndent(errorMessage, "", "\t")
fmt.Print(string(a))
}
{
"email": "email is required",
"name": "name is required"
}
pull requests are welcome