Added FormScanner custom scanner, updated Go version.

This commit is contained in:
jdl
2025-03-30 11:03:15 +02:00
parent 4993940aca
commit acbdcae5f9
3 changed files with 42 additions and 39 deletions

View File

@@ -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)