Skip to content

brainlabs/validator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Simple Struct Validator

example :

package main

import (
	"fmt"

	"github.com/brainlabs/validator"
)

type Person struct {
	Name       string   `json:"name" valid:"required|min:3|max:10|alpha_space"`
	Age        int      `json:"age" valid:"required|min:4|max:100"`
	Status     string   `json:"status" valid:"in:success,failed"`
	Address    *Address `json:"address" valid:"required"`
	Phone      string   `json:"phone" valid:"required|id_phone"`
}

type Address struct {
	AddressName string `json:"address_name" valid:"required|min:10|max:100"`
}



func main() {
	
	ps := &Person{
		Name:   "Jhon Doe",
		Age:    10,
		Status: "success",
		Address: &Address{
			//AddressName: "Street Walker Petir Jakarta No.20",
		},
		Phone: "62821020102010201",
	}

	vl := validator.New()
	result := vl.ValidateStruct(ps)

	fmt.Println(validator.DumpToString(result))

}

Author

About

go struct validator very simple

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages