mirror of
https://github.com/kataras/iris.git
synced 2025-12-21 03:47:04 +00:00
reorganization of _examples and add some new examples such as iris+groupcache+mysql+docker
Former-commit-id: ed635ee95de7160cde11eaabc0c1dcb0e460a620
This commit is contained in:
63
_examples/mvc/vuejs-todo-mvc/src/web/main.go
Normal file
63
_examples/mvc/vuejs-todo-mvc/src/web/main.go
Normal file
@@ -0,0 +1,63 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/kataras/iris/v12/_examples/mvc/vuejs-todo-mvc/src/todo"
|
||||
"github.com/kataras/iris/v12/_examples/mvc/vuejs-todo-mvc/src/web/controllers"
|
||||
|
||||
"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()
|
||||
|
||||
// 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",
|
||||
})
|
||||
|
||||
// create a sub router and register the http controllers.
|
||||
todosRouter := app.Party("/todos")
|
||||
|
||||
// create our mvc application targeted to /todos relative sub path.
|
||||
todosApp := mvc.New(todosRouter)
|
||||
|
||||
// any dependencies bindings here...
|
||||
todosApp.Register(
|
||||
todo.NewMemoryService(),
|
||||
)
|
||||
|
||||
todosController := new(controllers.TodoController)
|
||||
// controllers registration here...
|
||||
todosApp.Handle(todosController)
|
||||
|
||||
// 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
|
||||
})
|
||||
|
||||
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")
|
||||
}
|
||||
Reference in New Issue
Block a user