Skip to content

Commit 5705acf

Browse files
committed
feat(framework): load pkgs by default, request.MustSession
1 parent d182395 commit 5705acf

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

framework/framework.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
package framework
22

3-
import "github.com/studiolambda/cosmos/router"
3+
import (
4+
_ "github.com/studiolambda/cosmos/contract"
5+
_ "github.com/studiolambda/cosmos/problem"
6+
"github.com/studiolambda/cosmos/router"
7+
)
48

59
// Router is the HTTP router type used by Cosmos applications.
610
// It provides routing functionality with support for path parameters,

framework/request/session.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,25 @@ import (
44
"net/http"
55

66
"github.com/studiolambda/cosmos/contract"
7+
"github.com/studiolambda/cosmos/problem"
78
)
89

10+
var ErrSessionNotFound = problem.Problem{
11+
Title: "Session not found",
12+
Detail: "Unable to find the session in the request",
13+
Status: http.StatusInternalServerError,
14+
}
15+
916
func Session(r *http.Request, key any) (contract.Session, bool) {
1017
s, ok := r.Context().Value(key).(contract.Session)
1118

1219
return s, ok
1320
}
21+
22+
func MustSession(r *http.Request, key any) contract.Session {
23+
if s, ok := Session(r, key); ok {
24+
return s
25+
}
26+
27+
panic(ErrSessionNotFound)
28+
}

0 commit comments

Comments
 (0)