package routing import ( "net/http" lishwist "lishwist/core" "lishwist/http/response" ) func ExpectAppSession(next func(*lishwist.Session, http.Header, *response.Request) response.Response) response.HandlerFunc { return func(w http.Header, r *response.Request) response.Response { session := r.GetSession() username, ok := session.GetValue("username").(string) if !ok { return response.Error(http.StatusInternalServerError, "Something went wrong.").Log("Failed to get username from session") } appSession, err := lishwist.SessionFromUsername(username) if err != nil { return response.Error(http.StatusInternalServerError, "Something went wrong.").Log("Failed to get session by username %q: %s", username, err) } return next(appSession, w, r) } }