Skip to content
This repository was archived by the owner on Feb 7, 2024. It is now read-only.

Commit 8aec843

Browse files
jbenetStebalien
authored andcommitted
added Request and RequestDecode
related to #92
1 parent be6da7c commit 8aec843

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

shell.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,25 @@ func (s *Shell) newRequest(ctx context.Context, command string, args ...string)
9292
return NewRequest(ctx, s.url, command, args...)
9393
}
9494

95+
func (s *Shell) Request(ctx context.Context, command string, args ...string) (*Request, *Response, error) {
96+
req := s.newRequest(ctx, command, args...)
97+
res, err := req.Send(s.httpcli)
98+
return req, res, err
99+
}
100+
101+
func (s *Shell) RequestDecode(ctx context.Context, dec interface{}, command string, args ...string) error {
102+
_, res, err := s.Request(ctx, command, args...)
103+
if err != nil {
104+
return err
105+
}
106+
defer res.Close()
107+
if res.Error != nil {
108+
return res.Error
109+
}
110+
111+
return json.NewDecoder(res.Output).Decode(dec)
112+
}
113+
95114
type IdOutput struct {
96115
ID string
97116
PublicKey string

0 commit comments

Comments
 (0)