aboutsummaryrefslogtreecommitdiff
path: root/valid/valid.go
blob: 24f88841429b584043a576911f6c09e75dd76aaf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// Package valid contains the Valider interface.
//
// The Valider interface is used to verify the "validity" of a value, where "validity" is defined by the implementing type.
//
// All examples are assuming the following struct:
//
//	type Example struct {
//	    Name string
//	}
//
// Where possible, implementors should use errors.Join to allow for multiple validation errors to be returned:
//
//	func (e *Example) Valid() error {
//	    var errs []error
//	    if e.Name == "" {
//	        errs = append(errs, errors.New("name is empty"))
//	    }
//	    if len(errs) == 0 {
//	        return nil
//	    }
//	    return errors.Join(errs...)
//	}
package valid

// Interface is an interface for types that can be validated.
type Interface interface {
	// Valid returns any validation errors for the value. If the value is valid, nil is returned.
	//
	// Where possible, implementors should use errors.Join to allow for multiple validation errors to be returned.
	Valid() error
}