Skip to content

Commit f62304d

Browse files
committed
add response struct
1 parent fb0a20d commit f62304d

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

request.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,18 @@ import (
1414
"strings"
1515
)
1616

17+
//UploadResponse response struct
18+
type UploadResponse struct {
19+
FileID string `json:"fileId"`
20+
UploadedAt string `json:"uploadedAt"`
21+
Status string `json:"status"`
22+
Message string `json:"message"`
23+
Code string `json:"code"`
24+
}
25+
1726
// Upload uploads files with fileName
1827
// options are list of fieldSets constant
19-
func (s *Client) Upload(fileName string, options []string, workflowID string) (resp map[string]interface{}, err error) {
28+
func (s *Client) Upload(fileName string, options []string, workflowID string) (resp UploadResponse, err error) {
2029
payload := &bytes.Buffer{}
2130
writer := multipart.NewWriter(payload)
2231
file, err := os.Open(fileName)
@@ -64,7 +73,8 @@ func (s *Client) Upload(fileName string, options []string, workflowID string) (r
6473
if err != nil {
6574
return
6675
}
67-
json.Unmarshal(body, &resp)
76+
err = json.Unmarshal(body, &resp)
77+
6878
return
6979
}
7080

request_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func TestSypht_UploadFile(t *testing.T) {
3232
if err != nil {
3333
t.Error(err)
3434
}
35-
if resp["fileId"].(string) == "" {
35+
if resp.FileID == "" {
3636
t.Error("Empty fileID")
3737
}
3838
}
@@ -49,11 +49,11 @@ func TestSypht_PredictionWithCustomFieldSet(t *testing.T) {
4949
if err != nil {
5050
t.Error(err)
5151
}
52-
if resp["fileId"].(string) == "" {
52+
if resp.FileID == "" {
5353
t.Error("Empty fileID")
5454
}
5555
time.Sleep(time.Second * 10)
56-
_, err = client.Results(resp["fileId"].(string))
56+
_, err = client.Results(resp.FileID)
5757
if err != nil {
5858
t.Error(err)
5959
}

0 commit comments

Comments
 (0)