1
0
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:
Ggicci 2021-12-08 23:44:11 +08:00
parent 7754168f95
commit 27fbea875c
8 changed files with 15 additions and 15 deletions

View File

@ -7,13 +7,13 @@ import (
"reflect"
)
type Extractor struct {
type extractor struct {
multipart.Form
KeyNormalizer func(string) string
}
func NewExtractor(r *http.Request) *Extractor {
func newExtractor(r *http.Request) *extractor {
var form multipart.Form
if r.MultipartForm != nil {
@ -24,13 +24,13 @@ func NewExtractor(r *http.Request) *Extractor {
}
}
return &Extractor{
return &extractor{
Form: form,
KeyNormalizer: nil,
}
}
func (e *Extractor) Execute(ctx *DirectiveContext) error {
func (e *extractor) Execute(ctx *DirectiveContext) error {
for _, key := range ctx.Directive.Argv {
if e.KeyNormalizer != nil {
key = e.KeyNormalizer(key)
@ -42,7 +42,7 @@ func (e *Extractor) Execute(ctx *DirectiveContext) error {
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 {
return nil
}
@ -81,7 +81,7 @@ func (e *Extractor) extract(ctx *DirectiveContext, key string) error {
return nil
}
func (e *Extractor) extractMulti(ctx *DirectiveContext, key string) error {
func (e *extractor) extractMulti(ctx *DirectiveContext, key string) error {
var (
theSlice reflect.Value
elemType = ctx.ValueType.Elem()

View File

@ -7,7 +7,7 @@ import (
)
func init() {
RegisterTypeDecoder(reflect.TypeOf(File{}), FileTypeDecoderFunc(DecodeFile))
RegisterTypeDecoder(reflect.TypeOf(File{}), FileTypeDecoderFunc(decodeFile))
}
type File struct {
@ -16,7 +16,7 @@ type File struct {
Valid bool
}
func DecodeFile(fileHeader *multipart.FileHeader) (interface{}, error) {
func decodeFile(fileHeader *multipart.FileHeader) (interface{}, error) {
var inFile File
if fileHeader == nil {
return inFile, ErrNilFile

View File

@ -25,7 +25,7 @@ type UpdateGitHubIssueInput struct {
func TestMultipartForm_DecodeFile_WithInvalidFileHeaders(t *testing.T) {
Convey("Decode file with nil header", t, func() {
gotInput, err := DecodeFile(nil)
gotInput, err := decodeFile(nil)
So(errors.Is(err, ErrNilFile), ShouldBeTrue)
got, ok := gotInput.(File)
So(ok, ShouldBeTrue)
@ -37,7 +37,7 @@ func TestMultipartForm_DecodeFile_WithInvalidFileHeaders(t *testing.T) {
Filename: "avatar.png",
Size: 10,
}
gotInput, err := DecodeFile(fileHeader)
gotInput, err := decodeFile(fileHeader)
So(err, ShouldBeError)
got, ok := gotInput.(File)
So(ok, ShouldBeTrue)

View File

@ -3,5 +3,5 @@ package httpin
// formValueExtractor implements the "form" executor who extracts values from
// the forms of an HTTP request.
func formValueExtractor(ctx *DirectiveContext) error {
return NewExtractor(ctx.Request).Execute(ctx)
return newExtractor(ctx.Request).Execute(ctx)
}

View File

@ -28,7 +28,7 @@ func (chi *gochiURLParamExtractor) Execute(ctx *DirectiveContext) error {
}
}
extractor := &Extractor{
extractor := &extractor{
Form: multipart.Form{
Value: kvs,
},

View File

@ -34,7 +34,7 @@ func (mux *gorillaMuxVarsExtractor) Execute(ctx *DirectiveContext) error {
kvs[key] = []string{value}
}
extractor := &Extractor{
extractor := &extractor{
Form: multipart.Form{
Value: kvs,
},

View File

@ -8,7 +8,7 @@ import (
// headerValueExtractor implements the "header" executor who extracts values
// from the HTTP headers.
func headerValueExtractor(ctx *DirectiveContext) error {
extractor := &Extractor{
extractor := &extractor{
Form: multipart.Form{
Value: ctx.Request.Header,
},

View File

@ -5,7 +5,7 @@ import "mime/multipart"
// queryValueExtractor implements the "query" executor who extracts values from
// the querystring of an HTTP request.
func queryValueExtractor(ctx *DirectiveContext) error {
extractor := &Extractor{
extractor := &extractor{
Form: multipart.Form{
Value: ctx.Request.URL.Query(),
},