diff options
author | Igor Drozdov <idrozdov@gitlab.com> | 2019-05-20 12:35:03 +0300 |
---|---|---|
committer | Igor Drozdov <idrozdov@gitlab.com> | 2019-05-22 15:04:11 +0300 |
commit | a36cf8de6c2b5c03c68a54e207190627b5c651f2 (patch) | |
tree | 6d3a763536f7c9677347f2842c7b4b5b413408f5 /go/internal/gitlabnet/client.go | |
parent | 60280bbfc1a1cfb591bf01f3a06e828dcf97728a (diff) | |
download | gitlab-shell-a36cf8de6c2b5c03c68a54e207190627b5c651f2.tar.gz |
Introduce gitlabnet.ParseJSON to DRY
Diffstat (limited to 'go/internal/gitlabnet/client.go')
-rw-r--r-- | go/internal/gitlabnet/client.go | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/go/internal/gitlabnet/client.go b/go/internal/gitlabnet/client.go index c0f7f97..86add04 100644 --- a/go/internal/gitlabnet/client.go +++ b/go/internal/gitlabnet/client.go @@ -17,6 +17,10 @@ const ( secretHeaderName = "Gitlab-Shared-Secret" ) +var ( + ParsingError = fmt.Errorf("Parsing failed") +) + type ErrorResponse struct { Message string `json:"message"` } @@ -120,3 +124,11 @@ func (c *GitlabClient) doRequest(method, path string, data interface{}) (*http.R return response, nil } + +func ParseJSON(hr *http.Response, response interface{}) error { + if err := json.NewDecoder(hr.Body).Decode(response); err != nil { + return ParsingError + } + + return nil +} |