staticcheck fixes
This commit is contained in:
parent
7eaeecf586
commit
3ccca1aa3a
70
handlers.go
70
handlers.go
@ -21,6 +21,14 @@ import (
|
|||||||
|
|
||||||
// TODO: make this more generic.
|
// TODO: make this more generic.
|
||||||
|
|
||||||
|
type ctxKey string
|
||||||
|
|
||||||
|
func (c ctxKey) String() string {
|
||||||
|
return string(c)
|
||||||
|
}
|
||||||
|
|
||||||
|
const ownerKey = ctxKey("ownerid")
|
||||||
|
|
||||||
func OwnerCtx(next http.Handler) http.Handler {
|
func OwnerCtx(next http.Handler) http.Handler {
|
||||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
owner, err := app.getOwner(r)
|
owner, err := app.getOwner(r)
|
||||||
@ -29,16 +37,16 @@ func OwnerCtx(next http.Handler) http.Handler {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
ownerID := int64(owner.ID)
|
ownerID := int64(owner.ID)
|
||||||
ctx := context.WithValue(r.Context(), "ownerid", ownerID)
|
ctx := context.WithValue(r.Context(), ownerKey, ownerID)
|
||||||
next.ServeHTTP(w, r.WithContext(ctx))
|
next.ServeHTTP(w, r.WithContext(ctx))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func iconGET(w http.ResponseWriter, r *http.Request) {
|
func iconGET(w http.ResponseWriter, r *http.Request) {
|
||||||
ctx := r.Context()
|
ctx := r.Context()
|
||||||
ownerID, ok := ctx.Value("ownerid").(int64)
|
ownerID, ok := ctx.Value(ownerKey).(int64)
|
||||||
if !ok {
|
if !ok {
|
||||||
http.Error(w, http.StatusText(422), 422)
|
http.Error(w, http.StatusText(http.StatusUnprocessableEntity), http.StatusUnprocessableEntity)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
linkID, err := strconv.Atoi(chi.URLParam(r, "linkID"))
|
linkID, err := strconv.Atoi(chi.URLParam(r, "linkID"))
|
||||||
@ -91,14 +99,14 @@ func iconGET(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
w.Header().Add("Content-type", icon.ContentType)
|
w.Header().Add("Content-type", icon.ContentType)
|
||||||
w.WriteHeader(200)
|
w.WriteHeader(200)
|
||||||
_, err = w.Write(icon.Data)
|
_, _ = w.Write(icon.Data)
|
||||||
}
|
}
|
||||||
|
|
||||||
func watchitemGET(w http.ResponseWriter, r *http.Request) {
|
func watchitemGET(w http.ResponseWriter, r *http.Request) {
|
||||||
ctx := r.Context()
|
ctx := r.Context()
|
||||||
ownerID, ok := ctx.Value("ownerid").(int64)
|
ownerID, ok := ctx.Value(ownerKey).(int64)
|
||||||
if !ok {
|
if !ok {
|
||||||
http.Error(w, http.StatusText(422), 422)
|
http.Error(w, http.StatusText(http.StatusUnprocessableEntity), http.StatusUnprocessableEntity)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
watches, err := app.queries.GetAllWatchItemsByOwner(app.ctx, ownerID)
|
watches, err := app.queries.GetAllWatchItemsByOwner(app.ctx, ownerID)
|
||||||
@ -123,9 +131,9 @@ func watchitemGET(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
func watchitemDELETE(w http.ResponseWriter, r *http.Request) {
|
func watchitemDELETE(w http.ResponseWriter, r *http.Request) {
|
||||||
ctx := r.Context()
|
ctx := r.Context()
|
||||||
ownerID, ok := ctx.Value("ownerid").(int64)
|
ownerID, ok := ctx.Value(ownerKey).(int64)
|
||||||
if !ok {
|
if !ok {
|
||||||
http.Error(w, http.StatusText(422), 422)
|
http.Error(w, http.StatusText(http.StatusUnprocessableEntity), http.StatusUnprocessableEntity)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
watchID, err := strconv.Atoi(chi.URLParam(r, "watchID"))
|
watchID, err := strconv.Atoi(chi.URLParam(r, "watchID"))
|
||||||
@ -145,9 +153,9 @@ func watchitemPOST(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx := r.Context()
|
ctx := r.Context()
|
||||||
ownerID, ok := ctx.Value("ownerid").(int64)
|
ownerID, ok := ctx.Value(ownerKey).(int64)
|
||||||
if !ok {
|
if !ok {
|
||||||
http.Error(w, http.StatusText(422), 422)
|
http.Error(w, http.StatusText(http.StatusUnprocessableEntity), http.StatusUnprocessableEntity)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -155,7 +163,7 @@ func watchitemPOST(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
_, err := app.queries.AddWatchItem(app.ctx, *d)
|
_, err := app.queries.AddWatchItem(app.ctx, *d)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, http.StatusText(422), 422)
|
http.Error(w, err.Error(), http.StatusUnprocessableEntity)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -167,9 +175,9 @@ func pullrequestsPOST(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx := r.Context()
|
ctx := r.Context()
|
||||||
ownerID, ok := ctx.Value("ownerid").(int64)
|
ownerID, ok := ctx.Value(ownerKey).(int64)
|
||||||
if !ok {
|
if !ok {
|
||||||
http.Error(w, http.StatusText(422), 422)
|
http.Error(w, http.StatusText(http.StatusUnprocessableEntity), http.StatusUnprocessableEntity)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -177,16 +185,16 @@ func pullrequestsPOST(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
_, err := app.queries.AddPullRequest(app.ctx, *d)
|
_, err := app.queries.AddPullRequest(app.ctx, *d)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, http.StatusText(422), 422)
|
http.Error(w, err.Error(), http.StatusUnprocessableEntity)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func pullrequestsDELETE(w http.ResponseWriter, r *http.Request) {
|
func pullrequestsDELETE(w http.ResponseWriter, r *http.Request) {
|
||||||
ctx := r.Context()
|
ctx := r.Context()
|
||||||
ownerID, ok := ctx.Value("ownerid").(int64)
|
ownerID, ok := ctx.Value(ownerKey).(int64)
|
||||||
if !ok {
|
if !ok {
|
||||||
http.Error(w, http.StatusText(422), 422)
|
http.Error(w, http.StatusText(http.StatusUnprocessableEntity), http.StatusUnprocessableEntity)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
prID, err := strconv.Atoi(chi.URLParam(r, "prID"))
|
prID, err := strconv.Atoi(chi.URLParam(r, "prID"))
|
||||||
@ -201,9 +209,9 @@ func pullrequestsDELETE(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
func pullrequestsGET(w http.ResponseWriter, r *http.Request) {
|
func pullrequestsGET(w http.ResponseWriter, r *http.Request) {
|
||||||
ctx := r.Context()
|
ctx := r.Context()
|
||||||
ownerID, ok := ctx.Value("ownerid").(int64)
|
ownerID, ok := ctx.Value(ownerKey).(int64)
|
||||||
if !ok {
|
if !ok {
|
||||||
http.Error(w, http.StatusText(422), 422)
|
http.Error(w, http.StatusText(http.StatusUnprocessableEntity), http.StatusUnprocessableEntity)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
prs, err := app.queries.GetAllPullRequests(app.ctx, ownerID)
|
prs, err := app.queries.GetAllPullRequests(app.ctx, ownerID)
|
||||||
@ -228,9 +236,9 @@ func pullrequestsGET(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
func linksGET(w http.ResponseWriter, r *http.Request) {
|
func linksGET(w http.ResponseWriter, r *http.Request) {
|
||||||
ctx := r.Context()
|
ctx := r.Context()
|
||||||
ownerID, ok := ctx.Value("ownerid").(int64)
|
ownerID, ok := ctx.Value(ownerKey).(int64)
|
||||||
if !ok {
|
if !ok {
|
||||||
http.Error(w, http.StatusText(422), 422)
|
http.Error(w, http.StatusText(http.StatusUnprocessableEntity), http.StatusUnprocessableEntity)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
links, err := app.queries.GetAllLinksForOwner(app.ctx, ownerID)
|
links, err := app.queries.GetAllLinksForOwner(app.ctx, ownerID)
|
||||||
@ -260,9 +268,9 @@ func linksPOST(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx := r.Context()
|
ctx := r.Context()
|
||||||
ownerID, ok := ctx.Value("ownerid").(int64)
|
ownerID, ok := ctx.Value(ownerKey).(int64)
|
||||||
if !ok {
|
if !ok {
|
||||||
http.Error(w, http.StatusText(422), 422)
|
http.Error(w, http.StatusText(http.StatusUnprocessableEntity), http.StatusUnprocessableEntity)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -270,7 +278,7 @@ func linksPOST(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
_, err := app.queries.AddLink(app.ctx, *d)
|
_, err := app.queries.AddLink(app.ctx, *d)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, http.StatusText(422), 422)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -282,9 +290,9 @@ func prignorePOST(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx := r.Context()
|
ctx := r.Context()
|
||||||
ownerID, ok := ctx.Value("ownerid").(int64)
|
ownerID, ok := ctx.Value(ownerKey).(int64)
|
||||||
if !ok {
|
if !ok {
|
||||||
http.Error(w, http.StatusText(422), 422)
|
http.Error(w, http.StatusText(http.StatusUnprocessableEntity), http.StatusUnprocessableEntity)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -292,16 +300,16 @@ func prignorePOST(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
_, err := app.queries.AddPullRequestIgnore(app.ctx, *d)
|
_, err := app.queries.AddPullRequestIgnore(app.ctx, *d)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, http.StatusText(422), 422)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func linkDELETE(w http.ResponseWriter, r *http.Request) {
|
func linkDELETE(w http.ResponseWriter, r *http.Request) {
|
||||||
ctx := r.Context()
|
ctx := r.Context()
|
||||||
ownerID, ok := ctx.Value("ownerid").(int64)
|
ownerID, ok := ctx.Value(ownerKey).(int64)
|
||||||
if !ok {
|
if !ok {
|
||||||
http.Error(w, http.StatusText(422), 422)
|
http.Error(w, http.StatusText(http.StatusUnprocessableEntity), http.StatusUnprocessableEntity)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
linkID, err := strconv.Atoi(chi.URLParam(r, "linkID"))
|
linkID, err := strconv.Atoi(chi.URLParam(r, "linkID"))
|
||||||
@ -329,12 +337,12 @@ func index(w http.ResponseWriter, r *http.Request) {
|
|||||||
ctx := r.Context()
|
ctx := r.Context()
|
||||||
owner, err := app.getOwner(r)
|
owner, err := app.getOwner(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, http.StatusText(422), 422)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ownerID, ok := ctx.Value("ownerid").(int64)
|
ownerID, ok := ctx.Value(ownerKey).(int64)
|
||||||
if !ok {
|
if !ok {
|
||||||
http.Error(w, http.StatusText(422), 422)
|
http.Error(w, http.StatusText(http.StatusUnprocessableEntity), http.StatusUnprocessableEntity)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
dbCtx := context.Background()
|
dbCtx := context.Background()
|
||||||
|
Loading…
Reference in New Issue
Block a user