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 11package shell
22
33import (
4+ "bytes"
45 "encoding/json"
6+ "fmt"
7+ "io"
58 "io/ioutil"
69 "strings"
710
811 files "github.com/whyrusleeping/go-multipart-files"
912)
1013
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 ) {
1232 req := s .newRequest ("dag/put" )
1333 req .Opts = map [string ]string {
1434 "input-enc" : ienc ,
1535 "format" : kind ,
1636 }
1737
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+ }
1949 rc := ioutil .NopCloser (r )
2050 fr := files .NewReaderFile ("" , "" , rc , nil )
2151 slf := files .NewSliceFile ("" , "" , []files.File {fr })
You can’t perform that action at this time.
0 commit comments