From ce6558fbb53862fe31948f824ddb3b1b5902ec09 Mon Sep 17 00:00:00 2001 From: Michael Zhang Date: Tue, 20 Jul 2021 14:40:30 -0500 Subject: [PATCH] a --- Makefile | 5 ++++- go.mod | 1 + osuapi/beatmapsets.go | 3 ++- osuapi/osuapi.go | 16 ++++++++-------- 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index a92ed6a..8697591 100644 --- a/Makefile +++ b/Makefile @@ -6,4 +6,7 @@ all: subscribe-bot subscribe-bot: $(SOURCES) go build -o $@ -ldflags "-X main.GitCommit=$(GIT_COMMIT)" -.PHONY: all +checkFmt: + [ -z "$$(git ls-files | grep '\.go$$' | xargs gofmt -l)" ] || (exit 1) + +.PHONY: all checkFmt diff --git a/go.mod b/go.mod index 5b68ed2..36b0429 100644 --- a/go.mod +++ b/go.mod @@ -14,6 +14,7 @@ require ( github.com/go-git/go-git/v5 v5.2.0 github.com/gorilla/sessions v1.2.1 // indirect github.com/kofalt/go-memoize v0.0.0-20200917044458-9b55a8d73e1c + github.com/pkg/errors v0.8.1 go.etcd.io/bbolt v1.3.5 golang.org/x/sync v0.0.0-20201008141435-b3e1573b7520 ) diff --git a/osuapi/beatmapsets.go b/osuapi/beatmapsets.go index ed0a36b..fbbadfb 100644 --- a/osuapi/beatmapsets.go +++ b/osuapi/beatmapsets.go @@ -17,7 +17,8 @@ func (api *Osuapi) SearchBeatmaps(rankStatus string) (beatmapSearch BeatmapSearc url := "/beatmapsets/search?" + query err = api.Request("GET", url, &beatmapSearch) if err != nil { - return errors.Wrap("failed to search beatmaps") + errors.Wrap(err, "failed to search beatmaps") + return } return diff --git a/osuapi/osuapi.go b/osuapi/osuapi.go index adea136..e65db30 100644 --- a/osuapi/osuapi.go +++ b/osuapi/osuapi.go @@ -74,20 +74,20 @@ func (api *Osuapi) Token() (token string, err error) { strings.NewReader(data), ) if err != nil { - err = errors.Wrap("failed to make POST request") + err = errors.Wrap(err, "failed to make POST request") return } var osuToken OsuToken respBody, err := ioutil.ReadAll(resp.Body) if err != nil { - err = errors.Wrap("failed to read response body") + err = errors.Wrap(err, "failed to read response body") return } err = json.Unmarshal(respBody, &osuToken) if err != nil { - err = errors.Wrap("failed to unmarshal response body as json") + err = errors.Wrap(err, "failed to unmarshal response body as json") return } @@ -110,7 +110,7 @@ func (api *Osuapi) Request0(action string, url string) (resp *http.Response, err token, err := api.Token() if err != nil { - err = errors.Wrap("failed to fetch token") + err = errors.Wrap(err, "failed to fetch token") return } @@ -118,7 +118,7 @@ func (api *Osuapi) Request0(action string, url string) (resp *http.Response, err resp, err = api.httpClient.Do(req) if err != nil { - err = errors.Wrap("http client failed") + err = errors.Wrap(err, "http client failed") return } @@ -144,17 +144,17 @@ func (api *Osuapi) Request0(action string, url string) (resp *http.Response, err func (api *Osuapi) Request(action string, url string, result interface{}) (err error) { resp, err := api.Request0(action, url) if err != nil { - return errors.Wrap("base request failed") + return errors.Wrap(err, "base request failed") } data, err := ioutil.ReadAll(resp.Body) if err != nil { - return errors.Wrap("failed to read http response body") + return errors.Wrap(err, "failed to read http response body") } err = json.Unmarshal(data, result) if err != nil { - return errors.Wrap("failed to unmarshal http response as json") + return errors.Wrap(err, "failed to unmarshal http response as json") } return