-
Notifications
You must be signed in to change notification settings - Fork 0
/
option.go
49 lines (39 loc) · 2.41 KB
/
option.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package inreq
import (
"net/http"
"github.com/rrgmc/instruct"
"github.com/rrgmc/instruct/options"
)
type (
AnyOption = options.AnyOption[*http.Request, DecodeContext]
DefaultOption = options.DefaultOption[*http.Request, DecodeContext, defaultOptions]
DecodeOption = options.DecodeOption[*http.Request, DecodeContext, decodeOptions]
AnyTypeOption = options.AnyTypeOption[*http.Request, DecodeContext]
TypeDefaultOption = options.TypeDefaultOption[*http.Request, DecodeContext, typeDefaultOptions]
TypeDecodeOption = options.TypeDecodeOption[*http.Request, DecodeContext, decodeOptions]
DefaultAndTypeDefaultOption = options.DefaultAndTypeDefaultOption[*http.Request, DecodeContext, defaultOptions, typeDefaultOptions]
DefaultAndDecodeOption = options.DefaultAndDecodeOption[*http.Request, DecodeContext, defaultOptions, decodeOptions]
TypeDefaultAndTypeDecodeOption = options.TypeDefaultAndTypeDecodeOption[*http.Request, DecodeContext, typeDefaultOptions, decodeOptions]
DefaultAndTypeDefaultDecodeOption = options.DefaultAndTypeDefaultDecodeOption[*http.Request, DecodeContext, decodeOptions, decodeOptions]
TypeDefaultAndDecodeOption = options.TypeDefaultAndDecodeOption[*http.Request, DecodeContext, typeDefaultOptions, decodeOptions]
FullOption = options.FullOption[*http.Request, DecodeContext, defaultOptions, typeDefaultOptions, decodeOptions, decodeOptions]
)
// PathValue is used by the "path" operation to extract the path from the request. Usually this is stored
// in the context by libraries like "gorilla/mux".
type PathValue interface {
GetRequestPath(r *http.Request, name string) (found bool, value any, err error)
}
type PathValueFunc func(r *http.Request, name string) (found bool, value any, err error)
func (p PathValueFunc) GetRequestPath(r *http.Request, name string) (found bool, value any, err error) {
return p(r, name)
}
// BodyDecoder should unmarshal the body into "data".
// The default one supports JSON and XML.
type BodyDecoder interface {
// Unmarshal should unmarshal r.Body into data. If r.Body is read, "ctx.DecodedBody()" MUST be called
// even if there are read errors.
Unmarshal(ctx DecodeContext, typeParam string, r *http.Request, data any) (bool, any, error)
}
// FieldNameMapper maps a struct field name to the header/query/form field name.
// The default one uses [strings.ToLower].
type FieldNameMapper = instruct.FieldNameMapper