stillbox/internal/forms/forms.go

72 lines
1.1 KiB
Go
Raw Permalink Normal View History

2024-10-31 09:09:58 -04:00
package forms
import (
"errors"
"time"
)
var (
ErrNotStruct = errors.New("destination is not a struct")
ErrNotPointer = errors.New("destination is not a pointer")
ErrContentType = errors.New("bad content type")
)
const (
MaxMultipartMemory int64 = 1024 * 1024 // 1MB
2024-10-31 09:09:58 -04:00
)
type options struct {
tagOverride *string
parseTimeIn *time.Location
parseLocal bool
acceptBlank bool
maxMultipartMemory int64
defaultOmitEmpty bool
2024-10-31 09:09:58 -04:00
}
type Option func(*options)
func WithParseTimeInTZ(l *time.Location) Option {
return func(o *options) {
o.parseTimeIn = l
}
}
func WithParseLocalTime() Option {
return func(o *options) {
o.parseLocal = true
}
}
func WithAcceptBlank() Option {
return func(o *options) {
o.acceptBlank = true
}
}
func WithTag(t string) Option {
return func(o *options) {
o.tagOverride = &t
}
}
func WithMaxMultipartSize(s int64) Option {
return func(o *options) {
o.maxMultipartMemory = s
}
}
func WithOmitEmpty() Option {
return func(o *options) {
o.defaultOmitEmpty = true
}
}
2024-10-31 09:09:58 -04:00
func (o *options) Tag() string {
if o.tagOverride != nil {
return *o.tagOverride
}
return "form"
}