go/webutil/pathscaner.go

32 lines
471 B
Go
Raw Permalink Normal View History

2024-11-15 18:27:39 +00:00
package webutil
import (
"fmt"
"net/http"
)
type PathScanner struct {
r *http.Request
err error
}
func NewPathScanner(r *http.Request) *PathScanner {
return &PathScanner{r: r}
}
func (s *PathScanner) Scan(name string, val any) *PathScanner {
if s.err != nil {
return s
}
if err := scan(s.r.PathValue(name), val); err != nil {
s.err = fmt.Errorf("Error in field %s: %w", name, err)
}
return s
}
func (s *PathScanner) Error() error {
return s.err
}