-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfiles.go
67 lines (50 loc) · 1.33 KB
/
files.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/**
Copyright Contributors to the Feilong Project.
SPDX-License-Identifier: Apache-2.0
**/
package feilong
import (
"encoding/json"
)
// https://cloudlib4zvm.readthedocs.io/en/latest/restapi.html#import-file
type ImportFileOutput struct {
DestURL string `json:"dest_url"`
filesizeInBytes int `json:"filesize_in_bytes"`
MD5Sum string `json:"md5sum"`
}
type ImportFileResult struct {
OverallRC int `json:"overallRC"`
ReturnCode int `json:"rc"`
Reason int `json:"rs"`
ErrorMsg string `json:"errmsg"`
ModuleId int `json:"modID"`
Output ImportFileOutput `json:"output"`
}
func (c *Client) ImportFile(file []byte) (*ImportFileResult, error) {
var result ImportFileResult
body, err := c.doRequest("PUT", "/files", file)
if err != nil {
return nil, err
}
err = json.Unmarshal(body, &result)
if err != nil {
return nil, err
}
return &result, nil
}
// https://cloudlib4zvm.readthedocs.io/en/latest/restapi.html#export-file
type ExportFileParams struct {
SourceFile string `json:"source_file"`
}
type ExportFileResult struct {
Contents []byte
}
func (c *Client) ExportFile(params *ExportFileParams) (*ExportFileResult, error) {
var result ExportFileResult
body, err := json.Marshal(params)
if err != nil {
return nil, err
}
result.Contents, err = c.doRequest("POST", "/files", body)
return &result, err
}