1
0
mirror of https://github.com/kataras/iris.git synced 2025-12-18 18:37:05 +00:00

new simple _examples/README.md, wiki should live only inside kataras/iris/wiki and the provided e-book

Former-commit-id: 350eafb0f70f8433e394e103ff93fa332ee00a05
This commit is contained in:
Gerasimos (Makis) Maropoulos
2020-05-05 16:03:19 +03:00
parent f5e59c10e1
commit c10dd32ad7
28 changed files with 416 additions and 1166 deletions

View File

@@ -498,57 +498,65 @@ And finally our main application's endpoint.
package main
import (
"vuejs-todo-mvc/todo"
"vuejs-todo-mvc/web/controllers"
"strings"
"github.com/kataras/iris/v12"
"github.com/kataras/iris/v12/sessions"
"github.com/kataras/iris/v12/websocket"
"github.com/kataras/iris/v12/_examples/tutorial/vuejs-todo-mvc/src/todo"
"github.com/kataras/iris/v12/_examples/tutorial/vuejs-todo-mvc/src/web/controllers"
"github.com/kataras/iris/v12/mvc"
"github.com/kataras/iris/v12"
"github.com/kataras/iris/v12/mvc"
"github.com/kataras/iris/v12/sessions"
"github.com/kataras/iris/v12/websocket"
)
func main() {
app := iris.New()
app := iris.New()
// serve our app in public, public folder
// contains the client-side vue.js application,
// no need for any server-side template here,
// actually if you're going to just use vue without any
// back-end services, you can just stop afer this line and start the server.
app.HandleDir("/", "./public")
// serve our app in public, public folder
// contains the client-side vue.js application,
// no need for any server-side template here,
// actually if you're going to just use vue without any
// back-end services, you can just stop afer this line and start the server.
app.HandleDir("/", "./public")
// configure the http sessions.
sess := sessions.New(sessions.Config{
Cookie: "iris_session",
})
// configure the http sessions.
sess := sessions.New(sessions.Config{
Cookie: "iris_session",
})
// configure the websocket server.
ws := websocket.New(websocket.Config{})
// create a sub router and register the http controllers.
todosRouter := app.Party("/todos")
// create a sub router and register the client-side library for the iris websockets,
// you could skip it but iris websockets supports socket.io-like API.
todosRouter := app.Party("/todos")
// http://localhost:8080/todos/iris-ws.js
// serve the javascript client library to communicate with
// the iris high level websocket event system.
todosRouter.Any("/iris-ws.js", websocket.ClientHandler())
// create our mvc application targeted to /todos relative sub path.
todosApp := mvc.New(todosRouter)
// create our mvc application targeted to /todos relative sub path.
todosApp := mvc.New(todosRouter)
// any dependencies bindings here...
todosApp.Register(
todo.NewMemoryService(),
)
// any dependencies bindings here...
todosApp.Register(
todo.NewMemoryService(),
sess.Start,
ws.Upgrade,
)
todosController := new(controllers.TodoController)
// controllers registration here...
todosApp.Handle(todosController)
// controllers registration here...
todosApp.Handle(new(controllers.TodoController))
// Create a sub mvc app for websocket controller.
// Inherit the parent's dependencies.
todosWebsocketApp := todosApp.Party("/sync")
todosWebsocketApp.HandleWebsocket(todosController).
SetNamespace("todos").
SetEventMatcher(func(methodName string) (string, bool) {
return strings.ToLower(methodName), true
})
// start the web server at http://localhost:8080
app.Listen(":8080")
websocketServer := websocket.New(websocket.DefaultGorillaUpgrader, todosWebsocketApp)
idGenerator := func(ctx iris.Context) string {
id := sess.Start(ctx).ID()
return id
}
todosWebsocketApp.Router.Get("/", websocket.Handler(websocketServer, idGenerator))
// start the web server at http://localhost:8080
app.Listen(":8080")
}
```