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