This repository was archived by the owner on Feb 7, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +32
-2
lines changed Expand file tree Collapse file tree 1 file changed +32
-2
lines changed Original file line number Diff line number Diff line change 1
1
package shell
2
2
3
3
import (
4
+ "bytes"
4
5
"encoding/json"
6
+ "fmt"
7
+ "io"
5
8
"io/ioutil"
6
9
"strings"
7
10
8
11
files "github.com/whyrusleeping/go-multipart-files"
9
12
)
10
13
11
- func (s * Shell ) DagPut (data , ienc , kind string ) (string , error ) {
14
+ func (s * Shell ) DagGet (ref string , out interface {}) error {
15
+ req := s .newRequest ("dag/get" )
16
+ req .Args = []string {ref }
17
+
18
+ resp , err := req .Send (s .httpcli )
19
+ if err != nil {
20
+ return err
21
+ }
22
+ defer resp .Close ()
23
+
24
+ if resp .Error != nil {
25
+ return resp .Error
26
+ }
27
+
28
+ return json .NewDecoder (resp .Output ).Decode (out )
29
+ }
30
+
31
+ func (s * Shell ) DagPut (data interface {}, ienc , kind string ) (string , error ) {
12
32
req := s .newRequest ("dag/put" )
13
33
req .Opts = map [string ]string {
14
34
"input-enc" : ienc ,
15
35
"format" : kind ,
16
36
}
17
37
18
- r := strings .NewReader (data )
38
+ var r io.Reader
39
+ switch data := data .(type ) {
40
+ case string :
41
+ r = strings .NewReader (data )
42
+ case []byte :
43
+ r = bytes .NewReader (data )
44
+ case io.Reader :
45
+ r = data
46
+ default :
47
+ return "" , fmt .Errorf ("cannot current handle putting values of type %T" , data )
48
+ }
19
49
rc := ioutil .NopCloser (r )
20
50
fr := files .NewReaderFile ("" , "" , rc , nil )
21
51
slf := files .NewSliceFile ("" , "" , []files.File {fr })
You can’t perform that action at this time.
0 commit comments