A lightweight model validator written in Go.

validator

A lightweight model validator written in Go.

CircleCI codecov Go Report Card GoDoc Release

quickstart

package main

import (
	"fmt"
	v "github.com/go-the-way/validator"
)

func main() {
	result := v.New(&struct {
		int `validate:"min(10,fail)"`
	}{}).Validate()
	fmt.Println(result.Passed)
	fmt.Println(result.Messages())
}

Validators

Name Support Example Description
Min ([])(*)uint{8,64}, ([])(*)int{8,64}, ([])(*)float{32,64} validate:"min(N,invalid)" Every value must be >= N
Max ([])(*)uint{8,64}, ([])(*)int{8,64}, ([])(*)float{32,64} validate:"max(N,invalid)" Every value must be <= N
Length Array[Any], Slice[Any], string, Array[string], Slice[string] validate:"length(N,invalid)" Array[Any] or Slice[Any]: Array or Slice's Len must be == N
string: Value's Len must be == N
Array[string] or Slice[string]: Every Value's Len must be == N
MinLength Array[Any], Slice[Any], string, Array[string], Slice[string] validate:"minlength(N,invalid)" Array[Any] or Slice[Any]: Array or Slice's Len must be >= N
string: Value's Len must be >= N
Array[string] or Slice[string]: Every Value's Len must be >= N
MaxLength Array[Any], Slice[Any], string, Array[string], Slice[string] validate:"maxlength(N,invalid)" Array[Any] or Slice[Any]: Array or Slice's Len must be <= N
string: Value's Len must be <= N
Array[string] or Slice[string]: Every Value's Len must be <= N
Enum ([])(*)uint{8,64}, ([])(*)int{8,64}, ([])(*)float{32,64}, ([])(*)string validate:"enum(O,invalid)" Every value must be one of O
Regex ([])(*)string validate:"regex(RE,invalid)" Every value must be match RE
Owner
go-the-way
Another go the way!
go-the-way
Similar Resources

A demo project shows how to use validator to validate parameters

validator-demo This project is a demo project shows how to use validator to validate parameters use case install requirements go get github.com/favadi

Jan 10, 2022

Iran National Id, Bank Card Number, Mobile Number Validator for golang

Iran IDValidator Iran National Id, Bank Card Number, Mobile Number Validator for golang Installation go get -u github.com/mohammadv184/idvalidator Us

Dec 20, 2021

Gin Middleware to extract json tag value from playground validator's errors validation

Json Tag Extractor for Go-Playground Validator This is Gin Middleware that aim to extract json tag and than store it to FieldError.Field() object. Ins

Jan 14, 2022

Validator - Replace the validation framework used by gin

validator Replace the validation framework used by gin replace mod:replace githu

Jan 18, 2022

Provide check digit algorithms and calculators written in Go

checkdigit About Provide check digit algorithms and calculators written by Go. Provided methods Algorithms Luhn Verhoeff Damm Calculators ISBN-10 ISBN

Dec 17, 2022

go-playground-converter is formatter error response inspiration like express-validator in nodejs build on top go-playground-validator.

Go Playground Converter go-playground-converter is formatter error response inspiration like express-validator in nodejs build on top in go-playground

Dec 9, 2022

Traefik config validator: a CLI tool to (syntactically) validate your Traefik configuration filesTraefik config validator: a CLI tool to (syntactically) validate your Traefik configuration files

Traefik config validator: a CLI tool to (syntactically) validate your Traefik configuration filesTraefik config validator: a CLI tool to (syntactically) validate your Traefik configuration files

Traefik Config Validator Note This is currently pre-release software. traefik-config-validator is a CLI tool to (syntactically) validate your Traefik

Dec 16, 2021

Snake-validator - Snake validator with golang

snake-validator Overview The concept of Snake (the video game) has been around s

Jan 22, 2022

CRUDist Model Driven Web Development. Automagically generate CRUD APIs from your model.

CRUDist - Model Driven API Development Automagicaly create CRUD APIs for your gorm models. Example Model definition type BaseModel struct { ID

Nov 15, 2021

Transmo - Transform Model into another model based on struct for Go (Golang).

Transmo Transmo is a Go library for transform model into another model base on struct. This library detect your field name to copy that into another m

Jan 7, 2022

:balloon: A lightweight struct validator for Go

gody Go versions supported Installation go get github.com/guiferpa/gody/v2 Usage package main import ( "encoding/json" "fmt" "net/http"

Nov 19, 2022

go-actor is a lightweight message framework using actor model

go-actor go-actor is a lightweight message framework using actor model 初衷 想能在代码逻辑上方便的写无锁的同步rpc调用代码,同时又不会阻塞住其他服务对这个Actor的调用 一个Actor可以有多种身份,想能比较方便的分类管理A

Oct 21, 2022

🧀 Formaggo is a simple model checker inspired by TLA+, The checker and the models are written in Go

🧀 Formaggo. A cheesy exhaustive state checker in Go. Formaggo is a simple model checker inspired by TLA+. The checker and the models are written in G

Jan 23, 2022

Fast JSON parser and validator for Go. No custom structs, no code generation, no reflection

fastjson - fast JSON parser and validator for Go Features Fast. As usual, up to 15x faster than the standard encoding/json. See benchmarks. Parses arb

Jan 5, 2023

jio is a json schema validator similar to joi

jio is a json schema validator similar to joi

jio Make validation simple and efficient ! 中文文档 Why use jio? Parameter validation in Golang is really a cursing problem. Defining tags on structs is n

Dec 25, 2022

A norms and conventions validator for Terraform

This tool will help you ensure that a terraform folder answer to your norms and conventions rules. This can be really useful in several cases : You're

Nov 29, 2022

Clean architecture validator for go, like a The Dependency Rule and interaction between packages in your Go projects.

Clean architecture validator for go, like a The Dependency Rule and interaction between packages in your Go projects.

Clean Architecture checker for Golang go-cleanarch was created to keep Clean Architecture rules, like a The Dependency Rule and interaction between mo

Dec 31, 2022

Golang parameter validation, which can replace go-playground/validator, includes ncluding Cross Field, Map, Slice and Array diving, provides readable,flexible, configurable validation.

Golang parameter validation, which can replace go-playground/validator, includes ncluding Cross Field, Map, Slice and Array diving, provides readable,flexible, configurable validation.

Checker 中文版本 Checker is a parameter validation package, can be use in struct/non-struct validation, including cross field validation in struct, elemen

Dec 16, 2022

Baseledger core consensus for running validator, full and seed nodes

baseledger-core Baseledger core consensus client for running a validator, full or seed node. ⚠️ WARNING: this code has not been audited and is not rea

Jan 13, 2022
Comments
  • Type of string array or slice on `minlength`, `maxlength` and `length` VFun are useless.

    Type of string array or slice on `minlength`, `maxlength` and `length` VFun are useless.

    Go code

    type Person struct {
    	Name1 []string `validate:"minlength(10,Name1 length must be >= 10)"`
    	Name2 []string `validate:"maxlength(10,Name2 length must be <= 10)"`
    	Name3 []string `validate:"length(10,Name3 length must be = 10)"`
    }
    
  • Add supports recursive validate

    Add supports recursive validate

    Go code like following

    type Person struct {
    	ID   int    `validate:"min(10,ID must be >= 10)"`
    	Name string `validate:"minlength(10,Name length must be >= 10)"`
    
    	*Hobby `validate:"valid(T)"`
    }
    
    type Hobby struct {
    	Name string `validate:"enum(Sing|Dance|Swimming,Hobby Name must be one of Sing|Dance|Swimming)"`
    }
    
:balloon: A lightweight struct validator for Go

gody Go versions supported Installation go get github.com/guiferpa/gody/v2 Usage package main import ( "encoding/json" "fmt" "net/http"

Nov 19, 2022
jio is a json schema validator similar to joi
jio is a json schema validator similar to joi

jio Make validation simple and efficient ! 中文文档 Why use jio? Parameter validation in Golang is really a cursing problem. Defining tags on structs is n

Dec 25, 2022
A norms and conventions validator for Terraform

This tool will help you ensure that a terraform folder answer to your norms and conventions rules. This can be really useful in several cases : You're

Nov 29, 2022
Golang parameter validation, which can replace go-playground/validator, includes ncluding Cross Field, Map, Slice and Array diving, provides readable,flexible, configurable validation.
Golang parameter validation, which can replace go-playground/validator, includes ncluding Cross Field, Map, Slice and Array diving, provides readable,flexible, configurable validation.

Checker 中文版本 Checker is a parameter validation package, can be use in struct/non-struct validation, including cross field validation in struct, elemen

Dec 16, 2022
golang request validator

validator Golang 参数验证器,目前只支持POST请求,JSON格式参数验证 亮点 1、验证时只要有一个错误,错误信息立即返回 2、可自定义参数别名显示错误信息;详情见_example文件 使用 go mod -u github.com/one-gold-coin/validator

Sep 30, 2021
golang rule-based string validator

gosv golang rule-based string validator usage import "github.com/s0rg/gosv" var MyRules = []gosv.Rule{ gosv.MinLen(8), gosv.MaxLen(64), gosv.MinLo

Nov 20, 2021
Checker/validator for Hong Kong IDs

hkidchecker Checker/validator for Hong Kong IDs Description This Go package validates Hong Kong ID card IDs. Useful for example for validating form in

Oct 13, 2021
The Hyperscale InputFilter library provides a simple inputfilter chaining mechanism by which multiple filters and validator may be applied to a single datum in a user-defined order.

Hyperscale InputFilter Branch Status Coverage master The Hyperscale InputFilter library provides a simple inputfilter chaining mechanism by which mult

Oct 20, 2021
OpenShift OLM Catalog Validator

OpenShift OLM Catalog Validator Overview It is an external validator which can be used with Operator-SDK to check the vendor-like criteria to publish

Nov 22, 2021
Vat ID Validator for Germany

German Vat Validator service This project has been developed using Hexagonal architecture and repository pattern. How to run? docker-compose up -d Cal

Nov 4, 2021