Skip to content

Commit 7e581e6

Browse files
Merge pull request #948 from appwrite/refactor-go-improvments
Refactor go improvments
2 parents 92bbc9c + b291191 commit 7e581e6

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

src/SDK/Language/Go.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,9 @@ public function getFiles(): array
138138
*/
139139
public function getTypeName(array $parameter, array $spec = []): string
140140
{
141+
if (str_contains($parameter['description'], 'Collection attributes') || str_contains($parameter['description'], 'List of attributes')) {
142+
return '[]map[string]any';
143+
}
141144
return match ($parameter['type']) {
142145
self::TYPE_INTEGER => 'int',
143146
self::TYPE_NUMBER => 'float64',

templates/go/client.go.twig

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,34 @@ func (client *Client) FileUpload(url string, headers map[string]interface{}, par
163163
currentChunk = int64(resp.Result.(map[string]interface{})["chunksUploaded"].(float64))
164164
}
165165
}
166+
167+
if fileInfo.Size() <= client.ChunkSize {
168+
if uploadId != "" && uploadId != "unique()" {
169+
headers["x-appwrite-id"] = uploadId
170+
}
171+
inputFile.Data = make([]byte, fileInfo.Size())
172+
_, err := file.Read(inputFile.Data)
173+
if err != nil && err != io.EOF {
174+
return nil, err
175+
}
176+
params[paramName] = inputFile
177+
178+
result, err = client.Call("POST", url, headers, params)
179+
if err != nil {
180+
return nil, err
181+
}
182+
183+
var parsed map[string]interface{}
184+
if strings.HasPrefix(result.Type, "application/json") {
185+
err = json.Unmarshal([]byte(result.Result.(string)), &parsed)
186+
if err == nil {
187+
uploadId, _ = parsed["$id"].(string)
188+
}
189+
}
190+
191+
return result, nil
192+
}
193+
166194
for i := currentChunk; i < numChunks; i++ {
167195
chunkSize := client.ChunkSize
168196
offset := int64(i) * chunkSize

0 commit comments

Comments
 (0)