Personal Git forge.

Code git clone ssh://git.poy.ooo:6969/~poyo/farga ZIP
app/middleware/user-handle.go / 699B #f8217a34
Raw
package middlewareimport (	"context"	"farga/templating"	"net/http"	"github.com/google/uuid"	"github.com/gorilla/mux")var UserHandleKey = "userHandle"// manages retrieving user DB data.func UserHandle(store Store) mux.MiddlewareFunc {	return func(next http.Handler) http.Handler {		return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {			vars := mux.Vars(r)			userHandle := vars["user"]			user, err := store.UserHandle(userHandle)			if err != nil || user.ID == uuid.Nil {				templating.Render(w, r, "base", "not_found")				return			}			ctx := context.WithValue(r.Context(), UserHandleKey, user)			r = r.WithContext(ctx)			next.ServeHTTP(w, r)		})	}}