fix _benchmarks/iris-mvc-templates

Former-commit-id: 10b4952308c62b81eb7270b9e0b29ad0bb645bc5
This commit is contained in:
Gerasimos (Makis) Maropoulos 2017-12-31 20:33:33 +02:00
parent 4dbecf762c
commit 9e6691e5ce
6 changed files with 53 additions and 49 deletions

View File

@ -2,10 +2,16 @@ package controllers
import "github.com/kataras/iris/mvc" import "github.com/kataras/iris/mvc"
type AboutController struct{ mvc.Controller } type AboutController struct{}
func (c *AboutController) Get() { var aboutView = mvc.View{
c.Data["Title"] = "About" Name: "about.html",
c.Data["Message"] = "Your application description page." Data: map[string]interface{}{
c.Tmpl = "about.html" "Title": "About",
"Message": "Your application description page..",
},
}
func (c *AboutController) Get() mvc.View {
return aboutView
} }

View File

@ -2,10 +2,16 @@ package controllers
import "github.com/kataras/iris/mvc" import "github.com/kataras/iris/mvc"
type ContactController struct{ mvc.Controller } type ContactController struct{}
func (c *ContactController) Get() { var contactView = mvc.View{
c.Data["Title"] = "Contact" Name: "contact.html",
c.Data["Message"] = "Your contact page." Data: map[string]interface{}{
c.Tmpl = "contact.html" "Title": "Contact",
"Message": "Your contact page.",
},
}
func (c *ContactController) Get() mvc.View {
return contactView
} }

View File

@ -2,9 +2,13 @@ package controllers
import "github.com/kataras/iris/mvc" import "github.com/kataras/iris/mvc"
type IndexController struct{ mvc.Controller } type IndexController struct{}
func (c *IndexController) Get() { var indexView = mvc.View{
c.Data["Title"] = "Home Page" Name: "index.html",
c.Tmpl = "index.html" Data: map[string]interface{}{"Title": "Home Page"},
}
func (c *IndexController) Get() mvc.View {
return indexView
} }

View File

@ -1,16 +0,0 @@
package controllers
import "github.com/kataras/iris/mvc"
type IndexControllerStatic struct{ mvc.C }
var index = mvc.View{
Name: "index.html",
Data: map[string]interface{}{
"Title": "Home Page",
},
}
func (c *IndexControllerStatic) Get() mvc.View {
return index
}

View File

@ -25,7 +25,7 @@ var helloView = mvc.View{
// `mvc.Result` is just an interface with a `Dispatch` function. // `mvc.Result` is just an interface with a `Dispatch` function.
// `mvc.Response` and `mvc.View` are the built'n result type dispatchers // `mvc.Response` and `mvc.View` are the built'n result type dispatchers
// you can even create custom response dispatchers by // you can even create custom response dispatchers by
// implementing the `github.com/kataras/iris/mvc#Result` interface. // implementing the `github.com/kataras/iris/hero#Result` interface.
func (c *HelloController) Get() mvc.Result { func (c *HelloController) Get() mvc.Result {
return helloView return helloView
} }

View File

@ -1,5 +1,9 @@
# A Todo MVC Application using Iris and Vue.js # A Todo MVC Application using Iris and Vue.js
Vue.js is a front-end framework for building web applications using javascript. It has a blazing fast Virtual DOM renderer.
Iris is a back-end framework for building web applications using The Go Programming Language (disclaimer: author here). It's one of the fastest and featured web frameworks out there. We wanna use this to serve our "todo service".
## The Tools ## The Tools
Programming Languages are just tools for us, but we need a safe, fast and “cross-platform” programming language to power our service. Programming Languages are just tools for us, but we need a safe, fast and “cross-platform” programming language to power our service.
@ -20,10 +24,10 @@ Extensive information about downloading & installing Go can be found [here](http
Many articles have been written, in the past, that lead developers not to use a web framework because they are useless and "bad". I have to tell you that there is no such thing, it always depends on the (web) framework that youre going to use. At production environment, we dont have the time or the experience to code everything that we wanna use in the applications, and if we could are we sure that we can do better and safely than others? In short term: **Good frameworks are helpful tools for any developer, company or startup and "bad" frameworks are waste of time, crystal clear.** Many articles have been written, in the past, that lead developers not to use a web framework because they are useless and "bad". I have to tell you that there is no such thing, it always depends on the (web) framework that youre going to use. At production environment, we dont have the time or the experience to code everything that we wanna use in the applications, and if we could are we sure that we can do better and safely than others? In short term: **Good frameworks are helpful tools for any developer, company or startup and "bad" frameworks are waste of time, crystal clear.**
Youll need only two dependencies: Youll need two dependencies:
1. The Iris Web Framework, for our server-side requirements. Can be found [here](https://github.com/kataras/iris), latest v10. 1. Vue.js, for our client-side requirements. Download it from [here](https://vuejs.org/), latest v2.
2. Vue.js, for our client-side requirements. Download it from [here](https://vuejs.org/), latest v2. 2. The Iris Web Framework, for our server-side requirements. Can be found [here](https://github.com/kataras/iris), latest v10.
> If you have Go already installed then just execute `go get -u github.com/kataras/iris` to install the Iris Web Framework. > If you have Go already installed then just execute `go get -u github.com/kataras/iris` to install the Iris Web Framework.
@ -34,7 +38,7 @@ If we are all in the same page, its time to learn how we can create a live to
We're going to use a vue.js todo application which uses browser' We're going to use a vue.js todo application which uses browser'
s local storage and doesn't have any user-specified features like live sync between browser's tabs, you can find the original version inside the vue's [docs](https://vuejs.org/v2/examples/todomvc.html). s local storage and doesn't have any user-specified features like live sync between browser's tabs, you can find the original version inside the vue's [docs](https://vuejs.org/v2/examples/todomvc.html).
Assuming that you know how %GOPATH% works, create an empty folder with any name in the %GOPATH%/src directory, we will create those files: Assuming that you know how %GOPATH% works, create an empty folder, i.e "vuejs-todo-mvc" in the %GOPATH%/src directory, there you will create those files:
- web/public/js/app.js - web/public/js/app.js
- web/public/index.html - web/public/index.html
@ -48,7 +52,7 @@ _Read the comments in the source code, they may be very helpful_
### The client-side (vue.js) ### The client-side (vue.js)
```js ```js
/* file: web/public/js/app.js */ /* file: vuejs-todo-mvc/web/public/js/app.js */
// Full spec-compliant TodoMVC with Iris // Full spec-compliant TodoMVC with Iris
// and hash-based routing in ~200 effective lines of JavaScript. // and hash-based routing in ~200 effective lines of JavaScript.
@ -259,7 +263,7 @@ app.$mount('.todoapp')
Let's add our view, the static html. Let's add our view, the static html.
```html ```html
<!-- file: web/public/index.html --> <!-- file: vuejs-todo-mvc/web/public/index.html -->
<!doctype html> <!doctype html>
<html data-framework="vue"> <html data-framework="vue">
@ -339,7 +343,7 @@ Let's add our view, the static html.
Our view model. Our view model.
```go ```go
// file: todo/item.go // file: vuejs-todo-mvc/todo/item.go
package todo package todo
type Item struct { type Item struct {
@ -353,7 +357,7 @@ type Item struct {
Our service. Our service.
```go ```go
// file: todo/service.go // file: vuejs-todo-mvc/todo/service.go
package todo package todo
import ( import (
@ -405,11 +409,11 @@ func (s *MemoryService) Save(sessionOwner string, newItems []Item) error {
We are going to use some of the MVC functionalities of the iris web framework here but you can do the same with the standard API as well. We are going to use some of the MVC functionalities of the iris web framework here but you can do the same with the standard API as well.
```go ```go
// file: controllers/todo_controller.go // file: vuejs-todo-mvc/controllers/todo_controller.go
package controllers package controllers
import ( import (
"vuejs-todo-mvc/src/todo" "vuejs-todo-mvc/todo"
"github.com/kataras/iris" "github.com/kataras/iris"
"github.com/kataras/iris/mvc" "github.com/kataras/iris/mvc"
@ -476,8 +480,8 @@ And finally our main application's endpoint.
package main package main
import ( import (
"vuejs-todo-mvc/src/todo" "vuejs-todo-mvc/todo"
"vuejs-todo-mvc/src/web/controllers" "vuejs-todo-mvc/web/controllers"
"github.com/kataras/iris" "github.com/kataras/iris"
"github.com/kataras/iris/sessions" "github.com/kataras/iris/sessions"
@ -547,6 +551,12 @@ Open one or more browser tabs at: http://localhost:8080 and have fun!
The whole project, all the files you saw in this article are located at: https://github.com/kataras/iris/tree/master/_examples/tutorial/vuejs-todo-mvc The whole project, all the files you saw in this article are located at: https://github.com/kataras/iris/tree/master/_examples/tutorial/vuejs-todo-mvc
## References
https://vuejs.org/v2/examples/todomvc.html (using browser's local storage)
https://github.com/kataras/iris/tree/master/_examples/mvc (mvc examples and features overview repository)
## Thank you, once again ## Thank you, once again
Happy new year and thank you for your pattience, once again:) Don't hesitate to post any questions and provide feedback(I'm very active dev therefore you will be heard here!) Happy new year and thank you for your pattience, once again:) Don't hesitate to post any questions and provide feedback(I'm very active dev therefore you will be heard here!)
@ -555,9 +565,3 @@ Don't forget to check out my medium profile and twitter as well, I'm posting som
- https://medium.com/@kataras - https://medium.com/@kataras
- https://twitter.com/MakisMaropoulos - https://twitter.com/MakisMaropoulos
## References
https://vuejs.org/v2/examples/todomvc.html (using browser's local storage)
https://github.com/kataras/iris/tree/master/_examples/mvc (mvc examples and features overview repository)