Skip to content

Commit

Permalink
refactor(pgs): use http.ServeMux v1.22
Browse files Browse the repository at this point in the history
This change futher separates `pgs` from most of the other services.

One important change is refactoring our web router to use the new
`http.ServeMux` router that does a better job of routing with templated
strings.

Further, we try to leverage the `http.Handler` interface that removes
the need to use `context.Context` as much.
  • Loading branch information
neurosnap committed Oct 28, 2024
1 parent a74b874 commit 413f3a2
Show file tree
Hide file tree
Showing 8 changed files with 520 additions and 422 deletions.
15 changes: 12 additions & 3 deletions imgs/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,14 +173,16 @@ func anyPerm(proj *db.Project) bool {
func ImgRequest(w http.ResponseWriter, r *http.Request) {
subdomain := shared.GetSubdomain(r)
cfg := shared.GetCfg(r)
st := shared.GetStorage(r)
dbpool := shared.GetDB(r)
logger := shared.GetLogger(r)
username := shared.GetUsernameFromRequest(r)
analytics := shared.GetAnalyticsQueue(r)

user, err := dbpool.FindUserForName(username)
if err != nil {
logger.Info("rss feed not found", "user", username)
http.Error(w, "rss feed not found", http.StatusNotFound)
logger.Info("user not found", "user", username)
http.Error(w, "user not found", http.StatusNotFound)
return
}

Expand Down Expand Up @@ -234,7 +236,14 @@ func ImgRequest(w http.ResponseWriter, r *http.Request) {
}

fname := post.Filename
pgs.ServeAsset(fname, opts, true, anyPerm, w, r)
router := pgs.NewWebRouter(
cfg,
logger,
dbpool,
st,
analytics,
)
router.ServeAsset(fname, opts, true, anyPerm, w, r)
}

func FindImgPost(r *http.Request, user *db.User, slug string) (*db.Post, error) {
Expand Down
Loading

0 comments on commit 413f3a2

Please sign in to comment.