You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

github.com/jackdoe/validations

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/jackdoe/validations

v0.0.0-20201209005614-90bd45c247bb
Source
Go
Version published
Created
Source

gorm validation callback that has Validate() interface and https://github.com/asaskevich/govalidator support

Example:


type User struct {
	gorm.Model
	Name           string `valid:"required"`
	Password       string `valid:"length(6|20)"`
	SecurePassword string `valid:"numeric"`
	Email          string `valid:"email"`
	CompanyID      uint
	Company        Company
}

func (u *User) Validate() error {
	if u.Name == "invalid" {
		return errors.New("bad user name")
	}

	return nil
}

type Company struct {
	gorm.Model
	Name string
}

func (c *Company) Validate() error {
	if c.Name == "invalid" {
		return errors.New("bad company name")
	}

	return nil
}


func main() {
	db, err := gorm.Open(sqlite.Open("test.db"), &gorm.Config{})
	if err != nil {
		panic(err)
	}
	validations.RegisterCallbacks(db)
}

FAQs

Package last updated on 09 Dec 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts