mirror of
https://github.com/ggicci/httpin.git
synced 2024-11-24 08:32:45 +02:00
feat: eliminate rarely used apis
This commit is contained in:
parent
7754168f95
commit
27fbea875c
12
extractor.go
12
extractor.go
@ -7,13 +7,13 @@ import (
|
|||||||
"reflect"
|
"reflect"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Extractor struct {
|
type extractor struct {
|
||||||
multipart.Form
|
multipart.Form
|
||||||
|
|
||||||
KeyNormalizer func(string) string
|
KeyNormalizer func(string) string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewExtractor(r *http.Request) *Extractor {
|
func newExtractor(r *http.Request) *extractor {
|
||||||
var form multipart.Form
|
var form multipart.Form
|
||||||
|
|
||||||
if r.MultipartForm != nil {
|
if r.MultipartForm != nil {
|
||||||
@ -24,13 +24,13 @@ func NewExtractor(r *http.Request) *Extractor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return &Extractor{
|
return &extractor{
|
||||||
Form: form,
|
Form: form,
|
||||||
KeyNormalizer: nil,
|
KeyNormalizer: nil,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *Extractor) Execute(ctx *DirectiveContext) error {
|
func (e *extractor) Execute(ctx *DirectiveContext) error {
|
||||||
for _, key := range ctx.Directive.Argv {
|
for _, key := range ctx.Directive.Argv {
|
||||||
if e.KeyNormalizer != nil {
|
if e.KeyNormalizer != nil {
|
||||||
key = e.KeyNormalizer(key)
|
key = e.KeyNormalizer(key)
|
||||||
@ -42,7 +42,7 @@ func (e *Extractor) Execute(ctx *DirectiveContext) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *Extractor) extract(ctx *DirectiveContext, key string) error {
|
func (e *extractor) extract(ctx *DirectiveContext, key string) error {
|
||||||
if ctx.Context.Value(FieldSet) == true {
|
if ctx.Context.Value(FieldSet) == true {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -81,7 +81,7 @@ func (e *Extractor) extract(ctx *DirectiveContext, key string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *Extractor) extractMulti(ctx *DirectiveContext, key string) error {
|
func (e *extractor) extractMulti(ctx *DirectiveContext, key string) error {
|
||||||
var (
|
var (
|
||||||
theSlice reflect.Value
|
theSlice reflect.Value
|
||||||
elemType = ctx.ValueType.Elem()
|
elemType = ctx.ValueType.Elem()
|
||||||
|
4
file.go
4
file.go
@ -7,7 +7,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
RegisterTypeDecoder(reflect.TypeOf(File{}), FileTypeDecoderFunc(DecodeFile))
|
RegisterTypeDecoder(reflect.TypeOf(File{}), FileTypeDecoderFunc(decodeFile))
|
||||||
}
|
}
|
||||||
|
|
||||||
type File struct {
|
type File struct {
|
||||||
@ -16,7 +16,7 @@ type File struct {
|
|||||||
Valid bool
|
Valid bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func DecodeFile(fileHeader *multipart.FileHeader) (interface{}, error) {
|
func decodeFile(fileHeader *multipart.FileHeader) (interface{}, error) {
|
||||||
var inFile File
|
var inFile File
|
||||||
if fileHeader == nil {
|
if fileHeader == nil {
|
||||||
return inFile, ErrNilFile
|
return inFile, ErrNilFile
|
||||||
|
@ -25,7 +25,7 @@ type UpdateGitHubIssueInput struct {
|
|||||||
|
|
||||||
func TestMultipartForm_DecodeFile_WithInvalidFileHeaders(t *testing.T) {
|
func TestMultipartForm_DecodeFile_WithInvalidFileHeaders(t *testing.T) {
|
||||||
Convey("Decode file with nil header", t, func() {
|
Convey("Decode file with nil header", t, func() {
|
||||||
gotInput, err := DecodeFile(nil)
|
gotInput, err := decodeFile(nil)
|
||||||
So(errors.Is(err, ErrNilFile), ShouldBeTrue)
|
So(errors.Is(err, ErrNilFile), ShouldBeTrue)
|
||||||
got, ok := gotInput.(File)
|
got, ok := gotInput.(File)
|
||||||
So(ok, ShouldBeTrue)
|
So(ok, ShouldBeTrue)
|
||||||
@ -37,7 +37,7 @@ func TestMultipartForm_DecodeFile_WithInvalidFileHeaders(t *testing.T) {
|
|||||||
Filename: "avatar.png",
|
Filename: "avatar.png",
|
||||||
Size: 10,
|
Size: 10,
|
||||||
}
|
}
|
||||||
gotInput, err := DecodeFile(fileHeader)
|
gotInput, err := decodeFile(fileHeader)
|
||||||
So(err, ShouldBeError)
|
So(err, ShouldBeError)
|
||||||
got, ok := gotInput.(File)
|
got, ok := gotInput.(File)
|
||||||
So(ok, ShouldBeTrue)
|
So(ok, ShouldBeTrue)
|
||||||
|
2
form.go
2
form.go
@ -3,5 +3,5 @@ package httpin
|
|||||||
// formValueExtractor implements the "form" executor who extracts values from
|
// formValueExtractor implements the "form" executor who extracts values from
|
||||||
// the forms of an HTTP request.
|
// the forms of an HTTP request.
|
||||||
func formValueExtractor(ctx *DirectiveContext) error {
|
func formValueExtractor(ctx *DirectiveContext) error {
|
||||||
return NewExtractor(ctx.Request).Execute(ctx)
|
return newExtractor(ctx.Request).Execute(ctx)
|
||||||
}
|
}
|
||||||
|
2
gochi.go
2
gochi.go
@ -28,7 +28,7 @@ func (chi *gochiURLParamExtractor) Execute(ctx *DirectiveContext) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extractor := &Extractor{
|
extractor := &extractor{
|
||||||
Form: multipart.Form{
|
Form: multipart.Form{
|
||||||
Value: kvs,
|
Value: kvs,
|
||||||
},
|
},
|
||||||
|
@ -34,7 +34,7 @@ func (mux *gorillaMuxVarsExtractor) Execute(ctx *DirectiveContext) error {
|
|||||||
kvs[key] = []string{value}
|
kvs[key] = []string{value}
|
||||||
}
|
}
|
||||||
|
|
||||||
extractor := &Extractor{
|
extractor := &extractor{
|
||||||
Form: multipart.Form{
|
Form: multipart.Form{
|
||||||
Value: kvs,
|
Value: kvs,
|
||||||
},
|
},
|
||||||
|
@ -8,7 +8,7 @@ import (
|
|||||||
// headerValueExtractor implements the "header" executor who extracts values
|
// headerValueExtractor implements the "header" executor who extracts values
|
||||||
// from the HTTP headers.
|
// from the HTTP headers.
|
||||||
func headerValueExtractor(ctx *DirectiveContext) error {
|
func headerValueExtractor(ctx *DirectiveContext) error {
|
||||||
extractor := &Extractor{
|
extractor := &extractor{
|
||||||
Form: multipart.Form{
|
Form: multipart.Form{
|
||||||
Value: ctx.Request.Header,
|
Value: ctx.Request.Header,
|
||||||
},
|
},
|
||||||
|
2
query.go
2
query.go
@ -5,7 +5,7 @@ import "mime/multipart"
|
|||||||
// queryValueExtractor implements the "query" executor who extracts values from
|
// queryValueExtractor implements the "query" executor who extracts values from
|
||||||
// the querystring of an HTTP request.
|
// the querystring of an HTTP request.
|
||||||
func queryValueExtractor(ctx *DirectiveContext) error {
|
func queryValueExtractor(ctx *DirectiveContext) error {
|
||||||
extractor := &Extractor{
|
extractor := &extractor{
|
||||||
Form: multipart.Form{
|
Form: multipart.Form{
|
||||||
Value: ctx.Request.URL.Query(),
|
Value: ctx.Request.URL.Query(),
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user