blob: 27c34e3affa69c2d29240baee97fd6f2304bc622 (
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
|
package valid
import (
"errors"
"log/slog"
)
type Example struct {
Name string
}
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...)
}
func ExampleInterface_Valid() {
e := Example{Name: ""}
if err := e.Valid(); err != nil {
slog.Error("validation failed", "err", err)
}
}
|