mirror of
https://github.com/kataras/iris.git
synced 2026-01-23 20:05:59 +00:00
start of the vue + mvc example and a simple session binding
Former-commit-id: 994f00952352c93d270ad197cb843f3222fb37c0
This commit is contained in:
@@ -160,7 +160,6 @@ func (c *ControllerActivator) isReservedMethod(name string) bool {
|
||||
|
||||
// register all available, exported methods to handlers if possible.
|
||||
func (c *ControllerActivator) parseMethods() {
|
||||
|
||||
n := c.Type.NumMethod()
|
||||
for i := 0; i < n; i++ {
|
||||
m := c.Type.Method(i)
|
||||
|
||||
@@ -260,6 +260,12 @@ func (t *testControllerBindStruct) Get() {
|
||||
t.Ctx.Writef(t.TitlePointer.title + t.TitleValue.title + t.Other)
|
||||
}
|
||||
|
||||
// test if context can be binded to the controller's function
|
||||
// without need to declare it to a struct if not needed.
|
||||
func (t *testControllerBindStruct) GetCtx(ctx iris.Context) {
|
||||
ctx.StatusCode(iris.StatusContinue)
|
||||
}
|
||||
|
||||
type testControllerBindDeep struct {
|
||||
testControllerBindStruct
|
||||
}
|
||||
@@ -268,6 +274,7 @@ func (t *testControllerBindDeep) Get() {
|
||||
// t.testControllerBindStruct.Get()
|
||||
t.Ctx.Writef(t.TitlePointer.title + t.TitleValue.title + t.Other)
|
||||
}
|
||||
|
||||
func TestControllerBind(t *testing.T) {
|
||||
app := iris.New()
|
||||
// app.Logger().SetLevel("debug")
|
||||
@@ -287,6 +294,8 @@ func TestControllerBind(t *testing.T) {
|
||||
expected := t1 + t2
|
||||
e.GET("/").Expect().Status(iris.StatusOK).
|
||||
Body().Equal(expected)
|
||||
e.GET("/ctx").Expect().Status(iris.StatusContinue)
|
||||
|
||||
e.GET("/deep").Expect().Status(iris.StatusOK).
|
||||
Body().Equal(expected)
|
||||
}
|
||||
|
||||
17
mvc2/session_binder.go
Normal file
17
mvc2/session_binder.go
Normal file
@@ -0,0 +1,17 @@
|
||||
package mvc2
|
||||
|
||||
import (
|
||||
"github.com/kataras/iris/context"
|
||||
"github.com/kataras/iris/sessions"
|
||||
)
|
||||
|
||||
// Session -> TODO: think of move all bindings to
|
||||
// a different folder like "bindings"
|
||||
// so it will be used as .Bind(bindings.Session(manager))
|
||||
// or let it here but change the rest of the binding names as well
|
||||
// because they are not "binders", their result are binders to be percise.
|
||||
func Session(sess *sessions.Sessions) func(context.Context) *sessions.Session {
|
||||
return func(ctx context.Context) *sessions.Session {
|
||||
return sess.Start(ctx)
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"github.com/kataras/iris/sessions"
|
||||
)
|
||||
|
||||
var defaultManager = sessions.New(sessions.Config{})
|
||||
var defaultSessionManager = sessions.New(sessions.Config{})
|
||||
|
||||
// SessionController is a simple `Controller` implementation
|
||||
// which requires a binded session manager in order to give
|
||||
@@ -22,7 +22,7 @@ type SessionController struct {
|
||||
// It makes sure that its "Manager" field is filled
|
||||
// even if the caller didn't provide any sessions manager via the `app.Controller` function.
|
||||
func (s *SessionController) OnActivate(ca *ControllerActivator) {
|
||||
if didntBindManually := ca.BindIfNotExists(defaultManager); didntBindManually {
|
||||
if didntBindManually := ca.BindIfNotExists(defaultSessionManager); didntBindManually {
|
||||
ca.Router.GetReporter().Add(
|
||||
`MVC SessionController: couldn't find any "*sessions.Sessions" bindable value to fill the "Manager" field,
|
||||
therefore this controller is using the default sessions manager instead.
|
||||
|
||||
Reference in New Issue
Block a user