Added FormScanner custom scanner, updated Go version.
This commit is contained in:
@@ -8,9 +8,12 @@ import (
|
||||
|
||||
var ErrUnsupportedType = errors.New("unsupported type")
|
||||
|
||||
type FormScanFunc func(name string, val any) (bool, error)
|
||||
|
||||
type FormScanner struct {
|
||||
form url.Values
|
||||
err error
|
||||
form url.Values
|
||||
err error
|
||||
scanFunc FormScanFunc
|
||||
}
|
||||
|
||||
func NewFormScanner(form url.Values) *FormScanner {
|
||||
@@ -22,6 +25,14 @@ func (s *FormScanner) Scan(name string, val any) *FormScanner {
|
||||
return s
|
||||
}
|
||||
|
||||
if s.scanFunc != nil {
|
||||
ok, err := s.scanFunc(name, val)
|
||||
s.err = err
|
||||
if ok || err != nil {
|
||||
return s
|
||||
}
|
||||
}
|
||||
|
||||
switch v := val.(type) {
|
||||
case *bool:
|
||||
*v = s.form.Has(name)
|
||||
|
||||
Reference in New Issue
Block a user