Skip to content

Commit

Permalink
refactor(*): return FileHeader in the File method
Browse files Browse the repository at this point in the history
  • Loading branch information
iawia002 committed Jan 12, 2021
1 parent 1ecabda commit b8682af
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions service/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ type ValueContainer interface {
// or "multipart/form-data".
Form(key string) ([]string, bool)
// File returns a file reader when "Content-Type" is "multipart/form-data".
File(key string) (multipart.File, bool)
File(key string) (multipart.File, *multipart.FileHeader, bool)
// Body returns a reader to read data from request body.
// The reader only can read once.
Body() (reader io.ReadCloser, contentType string, ok bool)
Expand Down Expand Up @@ -152,9 +152,9 @@ func (c *container) removeEmpties(values []string) ([]string, bool) {
}

// File returns a file reader when "Content-Type" is "multipart/form-data".
func (c *container) File(key string) (multipart.File, bool) {
file, _, err := c.request.FormFile(key)
return file, err == nil
func (c *container) File(key string) (multipart.File, *multipart.FileHeader, bool) {
file, fileHeader, err := c.request.FormFile(key)
return file, fileHeader, err == nil
}

// Body returns a reader to read data from request body.
Expand Down
2 changes: 1 addition & 1 deletion service/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ func (g *FileParameterGenerator) Validate(name string, defaultValue interface{},
// Generate generates an object by data from value container.
func (g *FileParameterGenerator) Generate(ctx context.Context, vc ValueContainer, consumers []Consumer,
name string, target reflect.Type) (interface{}, error) {
file, ok := vc.File(name)
file, _, ok := vc.File(name)
if !ok {
return nil, nil
}
Expand Down

0 comments on commit b8682af

Please sign in to comment.