Skip to content

Commit

Permalink
Merge branch 'yitsushi:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
twocs committed Oct 7, 2023
2 parents 18a5be5 + 74f1c29 commit a665240
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
19 changes: 14 additions & 5 deletions core/multipart.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ import (
const numberOfPartsKeyValue = 2

type multipartField struct {
Type string
Name string
Value []byte
Ref string
Type string
Name string
Value []byte
Ref string
OmitEmpty bool
}

func parseMultipartFields(r BaseRequest) map[string]multipartField {
Expand All @@ -29,6 +30,10 @@ func parseMultipartFields(r BaseRequest) map[string]multipartField {
}

field := parseTag(tag)
if field.OmitEmpty && v.Field(i).IsZero() {
continue
}

if field.Name == "" {
field.Name = v.Type().Field(i).Name
}
Expand All @@ -46,7 +51,11 @@ func parseTag(tag string) multipartField {

for _, part := range strings.Split(tag, ",") {
if !strings.Contains(part, "=") {
field.Name = part
if part == "omitempty" {
field.OmitEmpty = true
} else {
field.Name = part
}

continue
}
Expand Down
2 changes: 1 addition & 1 deletion docs/patterns-and-structure.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Example multipart request struct:
```go
// CreateRequest represents a request to create a file.
type CreateRequest struct {
FolderID string `multipart:"folderId,type=field"`
FolderID string `multipart:"folderId,type=field,omitempty"`
Name string `multipart:"name,type=field"`
IsSensitive bool `multipart:"isSensitive,type=field"`
Force bool `multipart:"force,type=field"`
Expand Down
2 changes: 1 addition & 1 deletion services/drive/files/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

// CreateRequest represents a request to create a file.
type CreateRequest struct {
FolderID string `multipart:"folderId,type=field"`
FolderID string `multipart:"folderId,type=field,omitempty"`
Name string `multipart:"name,type=field"`
IsSensitive bool `multipart:"isSensitive,type=field"`
Force bool `multipart:"force,type=field"`
Expand Down

0 comments on commit a665240

Please sign in to comment.