1
0
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:
Gerasimos (Makis) Maropoulos
2017-12-14 05:56:23 +02:00
parent d72c649441
commit 0b2dcc76f5
12 changed files with 438 additions and 3 deletions

View File

@@ -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)

View File

@@ -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
View 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)
}
}

View File

@@ -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.