This commit is contained in:
Michael Zhang 2021-07-20 14:40:30 -05:00
parent a0f508b8c5
commit ce6558fbb5
Signed by: michael
GPG key ID: BDA47A31A3C8EE6B
4 changed files with 15 additions and 10 deletions

View file

@ -6,4 +6,7 @@ all: subscribe-bot
subscribe-bot: $(SOURCES) subscribe-bot: $(SOURCES)
go build -o $@ -ldflags "-X main.GitCommit=$(GIT_COMMIT)" 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

1
go.mod
View file

@ -14,6 +14,7 @@ require (
github.com/go-git/go-git/v5 v5.2.0 github.com/go-git/go-git/v5 v5.2.0
github.com/gorilla/sessions v1.2.1 // indirect github.com/gorilla/sessions v1.2.1 // indirect
github.com/kofalt/go-memoize v0.0.0-20200917044458-9b55a8d73e1c github.com/kofalt/go-memoize v0.0.0-20200917044458-9b55a8d73e1c
github.com/pkg/errors v0.8.1
go.etcd.io/bbolt v1.3.5 go.etcd.io/bbolt v1.3.5
golang.org/x/sync v0.0.0-20201008141435-b3e1573b7520 golang.org/x/sync v0.0.0-20201008141435-b3e1573b7520
) )

View file

@ -17,7 +17,8 @@ func (api *Osuapi) SearchBeatmaps(rankStatus string) (beatmapSearch BeatmapSearc
url := "/beatmapsets/search?" + query url := "/beatmapsets/search?" + query
err = api.Request("GET", url, &beatmapSearch) err = api.Request("GET", url, &beatmapSearch)
if err != nil { if err != nil {
return errors.Wrap("failed to search beatmaps") errors.Wrap(err, "failed to search beatmaps")
return
} }
return return

View file

@ -74,20 +74,20 @@ func (api *Osuapi) Token() (token string, err error) {
strings.NewReader(data), strings.NewReader(data),
) )
if err != nil { if err != nil {
err = errors.Wrap("failed to make POST request") err = errors.Wrap(err, "failed to make POST request")
return return
} }
var osuToken OsuToken var osuToken OsuToken
respBody, err := ioutil.ReadAll(resp.Body) respBody, err := ioutil.ReadAll(resp.Body)
if err != nil { if err != nil {
err = errors.Wrap("failed to read response body") err = errors.Wrap(err, "failed to read response body")
return return
} }
err = json.Unmarshal(respBody, &osuToken) err = json.Unmarshal(respBody, &osuToken)
if err != nil { 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 return
} }
@ -110,7 +110,7 @@ func (api *Osuapi) Request0(action string, url string) (resp *http.Response, err
token, err := api.Token() token, err := api.Token()
if err != nil { if err != nil {
err = errors.Wrap("failed to fetch token") err = errors.Wrap(err, "failed to fetch token")
return return
} }
@ -118,7 +118,7 @@ func (api *Osuapi) Request0(action string, url string) (resp *http.Response, err
resp, err = api.httpClient.Do(req) resp, err = api.httpClient.Do(req)
if err != nil { if err != nil {
err = errors.Wrap("http client failed") err = errors.Wrap(err, "http client failed")
return 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) { func (api *Osuapi) Request(action string, url string, result interface{}) (err error) {
resp, err := api.Request0(action, url) resp, err := api.Request0(action, url)
if err != nil { if err != nil {
return errors.Wrap("base request failed") return errors.Wrap(err, "base request failed")
} }
data, err := ioutil.ReadAll(resp.Body) data, err := ioutil.ReadAll(resp.Body)
if err != nil { 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) err = json.Unmarshal(data, result)
if err != nil { 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 return