first working version
This commit is contained in:
parent
372915e24d
commit
6da132106f
18 changed files with 519 additions and 96 deletions
31
pkg/api/client/helper.go
Normal file
31
pkg/api/client/helper.go
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
package client
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type Error struct {
|
||||
Message string `json:"message"`
|
||||
Status int `json:"status"`
|
||||
}
|
||||
|
||||
func decodeResp(resp *http.Response, v interface{}) error {
|
||||
if resp.Body == nil {
|
||||
return nil
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
if resp.StatusCode == 200 {
|
||||
if v == nil {
|
||||
return nil
|
||||
}
|
||||
return json.NewDecoder(resp.Body).Decode(&v)
|
||||
}
|
||||
var e Error
|
||||
err := json.NewDecoder(resp.Body).Decode(&e)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return errors.New(e.Message)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue