Compare commits

..

No commits in common. "main" and "v0.8.4" have entirely different histories.
main ... v0.8.4

View File

@ -8,9 +8,17 @@ import (
var ErrUnsupportedType = errors.New("unsupported type")
// FormScanFunc is a custom form scanner that can be used to scan custom
// types using the form scanner.
//
// It returns true if it recognizes the type of val, and an error if scanning
// fails.
type FormScanFunc func(name, formVal 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 +30,13 @@ func (s *FormScanner) Scan(name string, val any) *FormScanner {
return s
}
if s.ScanFunc != nil {
if ok, err := s.ScanFunc(name, s.form.Get(name), val); ok {
s.err = err
return s
}
}
switch v := val.(type) {
case *bool:
*v = s.form.Has(name)
@ -37,7 +52,3 @@ func (s *FormScanner) Scan(name string, val any) *FormScanner {
func (s *FormScanner) Error() error {
return s.err
}
func (s *FormScanner) SetError(err error) {
s.err = err
}