Skip to content

Commit

Permalink
Merge pull request #948 from appwrite/refactor-go-improvments
Browse files Browse the repository at this point in the history
Refactor go improvments
  • Loading branch information
christyjacob4 authored Aug 20, 2024
2 parents 92bbc9c + b291191 commit 7e581e6
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/SDK/Language/Go.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ public function getFiles(): array
*/
public function getTypeName(array $parameter, array $spec = []): string
{
if (str_contains($parameter['description'], 'Collection attributes') || str_contains($parameter['description'], 'List of attributes')) {
return '[]map[string]any';
}
return match ($parameter['type']) {
self::TYPE_INTEGER => 'int',
self::TYPE_NUMBER => 'float64',
Expand Down
28 changes: 28 additions & 0 deletions templates/go/client.go.twig
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,34 @@ func (client *Client) FileUpload(url string, headers map[string]interface{}, par
currentChunk = int64(resp.Result.(map[string]interface{})["chunksUploaded"].(float64))
}
}

if fileInfo.Size() <= client.ChunkSize {
if uploadId != "" && uploadId != "unique()" {
headers["x-appwrite-id"] = uploadId
}
inputFile.Data = make([]byte, fileInfo.Size())
_, err := file.Read(inputFile.Data)
if err != nil && err != io.EOF {
return nil, err
}
params[paramName] = inputFile

result, err = client.Call("POST", url, headers, params)
if err != nil {
return nil, err
}

var parsed map[string]interface{}
if strings.HasPrefix(result.Type, "application/json") {
err = json.Unmarshal([]byte(result.Result.(string)), &parsed)
if err == nil {
uploadId, _ = parsed["$id"].(string)
}
}

return result, nil
}

for i := currentChunk; i < numChunks; i++ {
chunkSize := client.ChunkSize
offset := int64(i) * chunkSize
Expand Down

0 comments on commit 7e581e6

Please sign in to comment.