Skip to content

Commit

Permalink
Merge pull request #50 from leancloud/metadata-typo
Browse files Browse the repository at this point in the history
fix: typo
  • Loading branch information
weakish authored Dec 20, 2021
2 parents bc8711a + d4ac444 commit 7d89f2f
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 20 deletions.
2 changes: 1 addition & 1 deletion leancloud/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ func encodeFile(file *File, embedded bool) map[string]interface{} {
"__type": "File",
"name": file.Name,
"mime_type": file.MIME,
"metaData": file.Meatadata,
"metaData": file.MetaData,
}
}

Expand Down
16 changes: 8 additions & 8 deletions leancloud/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ import (

type File struct {
Object
Key string `json:"key"`
Name string `json:"name"`
Provider string `json:"provider"`
Bucket string `json:"bucket"`
MIME string `json:"mime_type"`
URL string `json:"url"`
Size int64 `json:"size"`
Meatadata map[string]interface{} `json:"metadata"`
Key string `json:"key"`
Name string `json:"name"`
Provider string `json:"provider"`
Bucket string `json:"bucket"`
MIME string `json:"mime_type"`
URL string `json:"url"`
Size int64 `json:"size"`
MetaData map[string]interface{} `json:"metadata"`
}

func (file *File) fetchOwner(client *Client, authOptions ...AuthOption) (*User, error) {
Expand Down
20 changes: 10 additions & 10 deletions leancloud/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ func (ref *Files) Upload(file *File, reader io.ReadSeeker, authOptions ...AuthOp
file.Size = size
}

if reflect.ValueOf(file.Meatadata).IsNil() {
file.Meatadata = make(map[string]interface{})
if reflect.ValueOf(file.MetaData).IsNil() {
file.MetaData = make(map[string]interface{})
}
file.Meatadata["size"] = file.Size
file.MetaData["size"] = file.Size
if owner != nil {
file.Meatadata["owner"] = owner.ID
file.MetaData["owner"] = owner.ID
} else {
file.Meatadata["owner"] = "unknown"
file.MetaData["owner"] = "unknown"
}

token, uploadURL, err := file.fetchToken(ref.c, authOptions...)
Expand Down Expand Up @@ -90,18 +90,18 @@ func (ref *Files) Upload(file *File, reader io.ReadSeeker, authOptions ...AuthOp

// UploadFromURL create an object of file in _File class with given file's url
func (ref *Files) UploadFromURL(file *File, authOptions ...AuthOption) error {
if reflect.ValueOf(file.Meatadata).IsNil() {
file.Meatadata = make(map[string]interface{})
if reflect.ValueOf(file.MetaData).IsNil() {
file.MetaData = make(map[string]interface{})
}
owner, err := file.fetchOwner(ref.c, authOptions...)
if err != nil {
return fmt.Errorf("unexpected error when fetch owner: %v", err)
}
file.Meatadata["__source"] = "external"
file.MetaData["__source"] = "external"
if owner != nil {
file.Meatadata["owner"] = owner.ID
file.MetaData["owner"] = owner.ID
} else {
file.Meatadata["owner"] = "unknown"
file.MetaData["owner"] = "unknown"
}

path := "/1.1/files"
Expand Down
2 changes: 1 addition & 1 deletion leancloud/files_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func TestFilesUploadFromFile(t *testing.T) {
defer os.Remove(filename)

file := &File{
Meatadata: map[string]interface{}{
MetaData: map[string]interface{}{
"comment": "This is a comment of Metadata",
},
}
Expand Down

0 comments on commit 7d89f2f

Please sign in to comment.