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