Skip to content

go generate support #1

@notnil

Description

@notnil

The Validate function could be generated with code representing the gator struct tags. For example:

type BigStruct struct {
    Required        string      `gator:”nonzero”`
    Email           string      `gator:”email”`
    DayOfWeek       int         `gator:”gte(0) | lt(7)”`
}

would generate:

func (b *BigStruct) Validate() error {
   return gator.New().Add(
        gator.NewField("Required", b.Required, gator.Nonzero()),
        gator.NewField("Email", b.Email, gator.Email()),
        gator.NewField("DayOfWeek", b.DayOfWeek, gator.Gte(0)),
        gator.NewField("DayOfWeek", b.DayOfWeek, gator.Lt(7)),
   ).Validate()
}

This would have all the advantages of compile time validation.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions