All Projects → gobuffalo → Validate

gobuffalo / Validate

Licence: mit
This package provides a framework for writing validations for Go applications.

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to Validate

Objection Unique
Unique validation for Objection.js
Stars: ✭ 42 (-26.32%)
Mutual labels:  validation, models
apple-receipt
Apple InAppPurchase Receipt - Models, Parser, Validator
Stars: ✭ 25 (-56.14%)
Mutual labels:  validation, models
Vue Mc
Models and Collections for Vue
Stars: ✭ 588 (+931.58%)
Mutual labels:  validation, models
Zaml
The Final Form of configuration files
Stars: ✭ 45 (-21.05%)
Mutual labels:  validation
Mobx React Form
Reactive MobX Form State Management
Stars: ✭ 1,031 (+1708.77%)
Mutual labels:  validation
Segmentationcpp
A c++ trainable semantic segmentation library based on libtorch (pytorch c++). Backbone: ResNet, ResNext. Architecture: FPN, U-Net, PAN, LinkNet, PSPNet, DeepLab-V3, DeepLab-V3+ by now.
Stars: ✭ 49 (-14.04%)
Mutual labels:  models
Dry Validation
Validation library with type-safe schemas and rules
Stars: ✭ 1,087 (+1807.02%)
Mutual labels:  validation
Pycard
A simple credit card validation Python library with no dependencies
Stars: ✭ 40 (-29.82%)
Mutual labels:  validation
Cpf
Validar, formatar e gerar números de CPF (validate, format and generate CPF numbers 🇧🇷).
Stars: ✭ 51 (-10.53%)
Mutual labels:  validation
Laravel Smart
Automatic Migrations, Validation and More
Stars: ✭ 48 (-15.79%)
Mutual labels:  validation
Celebrate
A joi validation middleware for Express.
Stars: ✭ 1,041 (+1726.32%)
Mutual labels:  validation
Validation
Simple PHP helper class for Validation.
Stars: ✭ 46 (-19.3%)
Mutual labels:  validation
Schemas
All schemas used for validation that are shared between our projects
Stars: ✭ 51 (-10.53%)
Mutual labels:  validation
Herosaver
An educational tool for exporting stl from THREE.js
Stars: ✭ 55 (-3.51%)
Mutual labels:  models
Arg.js
🇦🇷 🛠 NPM library. Validation of Argentinian bank account numbers, IDs and phone numbers
Stars: ✭ 52 (-8.77%)
Mutual labels:  validation
Inicpp
C++ parser of INI files with schema validation.
Stars: ✭ 47 (-17.54%)
Mutual labels:  validation
Usetheform
React library for composing declarative forms, manage their state, handling their validation and much more.
Stars: ✭ 40 (-29.82%)
Mutual labels:  validation
Laravel5 Genderize Api Client
Laravel 5 client for the Genderize.io API
Stars: ✭ 47 (-17.54%)
Mutual labels:  validation
Vs Validation
Common input and integrity validation routines for Visual Studio and other applications
Stars: ✭ 48 (-15.79%)
Mutual labels:  validation
Cinemanet
Stars: ✭ 57 (+0%)
Mutual labels:  models

github.com/gobuffalo/validate

Build Status GoDoc

This package provides a framework for writing validations for Go applications. It does provide you with few validators, but if you need others you can easly build them.

Installation

$ go get github.com/gobuffalo/validate

Usage

Using validate is pretty easy, just define some Validator objects and away you go.

Here is a pretty simple example:

package main

import (
	"log"

	v "github.com/gobuffalo/validate"
)

type User struct {
	Name  string
	Email string
}

func (u *User) IsValid(errors *v.Errors) {
	if u.Name == "" {
		errors.Add("name", "Name must not be blank!")
	}
	if u.Email == "" {
		errors.Add("email", "Email must not be blank!")
	}
}

func main() {
	u := User{Name: "", Email: ""}
	errors := v.Validate(&u)
	log.Println(errors.Errors)
  // map[name:[Name must not be blank!] email:[Email must not be blank!]]
}

In the previous example I wrote a single Validator for the User struct. To really get the benefit of using go-validator, as well as the Go language, I would recommend creating distinct validators for each thing you want to validate, that way they can be run concurrently.

package main

import (
	"fmt"
	"log"
	"strings"

	v "github.com/gobuffalo/validate"
)

type User struct {
	Name  string
	Email string
}

type PresenceValidator struct {
	Field string
	Value string
}

func (v *PresenceValidator) IsValid(errors *v.Errors) {
	if v.Value == "" {
		errors.Add(strings.ToLower(v.Field), fmt.Sprintf("%s must not be blank!", v.Field))
	}
}

func main() {
	u := User{Name: "", Email: ""}
	errors := v.Validate(&PresenceValidator{"Email", u.Email}, &PresenceValidator{"Name", u.Name})
	log.Println(errors.Errors)
        // map[name:[Name must not be blank!] email:[Email must not be blank!]]
}

That's really it. Pretty simple and straight-forward Just a nice clean framework for writing your own validators. Use in good health.

Built-in Validators

To make it even simpler, this package has a children package with some nice built-in validators.

package main

import (
	"log"

	"github.com/gobuffalo/validate"
	"github.com/gobuffalo/validate/validators"
)

type User struct {
	Name  string
	Email string
}


func main() {
	u := User{Name: "", Email: ""}
	errors := validate.Validate(
		&validators.EmailIsPresent{Name: "Email", Field: u.Email, Message: "Mail is not in the right format."},
		&validators.StringIsPresent{Field: u.Name, Name: "Name"},
	)
	log.Println(errors.Errors)
	// map[name:[Name can not be blank.] email:[Mail is not in the right format.]]
}

All fields are required for each validators, except Message (every validator has a default error message).

Available Validators

A full list of available validators can be found at https://godoc.org/github.com/gobuffalo/validate/validators.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].