Spaces:
Configuration error
Configuration error
File size: 647 Bytes
7beb700 f3f5b2d 7beb700 f3f5b2d 7beb700 f3f5b2d 7beb700 f3f5b2d 7beb700 f3f5b2d 7beb700 1301478 9b01f9a f3f5b2d 9b01f9a 7beb700 f3f5b2d 7beb700 f3f5b2d 7beb700 | 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 32 33 34 35 36 | package validation
import (
"context"
"time"
"gorm.io/gorm"
)
type ErrorMessage struct {
Field string `json:"field"`
Message string `json:"-"`
}
func New(db *gorm.DB) (*Validator, error) {
// Create source with 5 minute cache expiry
expiry := 5 * time.Minute
dbSource, err := NewDBOptionSource(db, expiry)
if err != nil {
return nil, err
}
// Start background refresh every 5 minutes
ctx := context.Background()
dbSource.StartAutoRefresh(ctx, 5*time.Minute)
// create validator
validator := NewValidator(dbSource)
if err := validator.RegisterAllCustomRules(); err != nil {
return nil, err
}
return validator, nil
}
|