invopop / validation

An idiomatic Go validation package. Supports configurable and extensible validation rules (validators) using normal language constructs instead of error-prone struct tags.
MIT License
81 stars 5 forks source link

Endless loop #5

Closed pdxrlj closed 9 months ago

pdxrlj commented 10 months ago

type Collection struct {
    Name   string `json:"name" validate:"required"`
    Column
}

func (c *Collection) Validate() error {
    return validation.Validate(&c,
        validation.By(func(value interface{}) error {
            //collection := value.(*Collection)
            fmt.Printf("=============================\n")
            //err := validation.Validate(collection.Name,
            //  validation.Required.Error("表名不能为空"),
            //  validation.Length(1, 30).Error("表名长度必须在1-30之间"),
            //)
            //if err != nil {
            //  return errors.WithStack(err)
            //}
            //column := collection.Column
            //err = validation.Validate(column.Create,
            //  validation.Each(ColumnAddValidateRule()),
            //)
            //if err != nil {
            //  return errors.WithStack(err)
            //}
            return nil
        }),

        //validation.Field(&c.Column.Drop, validation.When(len(c.Column.Drop) > 0, validation.Each(validation.Required))),
        //validation.Field(&c.Column.Rename, validation.When(len(c.Column.Rename) > 0, validation.Each(validation.Required))),
        //validation.Field(&c.Column.Modify, validation.When(len(c.Column.Modify) > 0), ColumnModifyRule()),
        //validation.Field(&c.Column.Index, validation.When(len(c.Column.Index.Drop) > 0, validation.Each(validation.Required))),
        //validation.Field(&c.Column.Partition, validation.When(len(c.Column.Partition.Add) > 0, ColumnPartitionRule())),
    )
}
timmattison commented 9 months ago

Is there more code that goes along with this? I'm missing:

Column struct
Create function
ColumnAddValidateRule function
errors.WithStack function
ColumnPartitionRule function
ColumnModifyRule function
pdxrlj commented 9 months ago

remove 的 func (c *Collection) Validate() error Validate function is ok