Revel
Web Framework
Pan Zebra
Go for web
net/http
> ListenAndServe
> HandlerFunc
> ResponseWriter
> Request
> Redirect
html/template
> ParseFiles
Revel
> MVC (routing, param parsing, validation,
templating)
> hot reload
> session/flash
> caching
> jobs
> testing
> internationalization
Project setup
$ revel new myapp
$ revel run myapp
.
├── app
│ ├── controllers
│ ├── init.go
│ ├── routes
│ ├── tmp
│ └── views
├── conf
│ ├── app.conf
│ └── routes
├── messages
│ └── sample.en
├── public
│ ├── css
│ ├── img
│ └── js
├── README.md
├── test-results
│ ├── app.log
│ ├── AppTest.passed.html
│ └── result.passed
└── tests
└── apptest.go
~
~ revel! http://revel.github.io
~
INFO 2015/01/11 17:54:21 revel.go:326: Loaded module testrunner
INFO 2015/01/11 17:54:21 revel.go:326: Loaded module static
INFO 2015/01/11 17:54:21 run.go:57: Running myapp (myapp) in dev mode
INFO 2015/01/11 17:54:21 harness.go:165: Listening on :9000
Request flow
> Go HTTP server -> goroutine!
0. handler -> filter chain
Filters (middleware) - processing pipeline
Request flow
> Go HTTP server -> goroutine!
0. handler -> filter chain
1. filters (processing) -> action
2. action (controller) -> result
Action & Result & Controller
A> method on Controller
A> is exported
A> returns revel.Result
R> implements func Apply(*Request, *Response)
C> type embeds *revel.Controller
C> context of request
Request flow
> Go HTTP server -> goroutine!
0. handler -> filter chain
1. filters (processing) -> action
2. action (controller) -> result
3. handler -> response
Templates
> Go templates
> searched by Controller/Action name
> case insensitive names
> data-binding
> additional functions (fields, set etc.)
> custom functions
Session & Flash
S> string map (crypto-signed cookie)
S> serialize to store
S> default lifetime == browser lifetime
F> overwritten on each request
F> Post/Redirect/Get
Jobs (module)
> modules are optional
> asynchronous
> outside main routine
> event-driven (user <action>, on startup,
scheduled)
/@jobs (watch interactively)
Testing (module)
> run
/@tests (interactive) OR $ revel test myapp
> type embeds revel.TestSuite
> No fixtures, test loggers
Summing-up
> comprehensive
> clear dir tree
> MVC
> jobs
> testing
> missing ORM (?)
Links
> Web Apps in Go (codewalk)
> Revel docs
> Web Frameworks in Go

Introducing Revel

  • 1.
  • 2.
    Go for web net/http >ListenAndServe > HandlerFunc > ResponseWriter > Request > Redirect html/template > ParseFiles
  • 3.
    Revel > MVC (routing,param parsing, validation, templating) > hot reload > session/flash > caching > jobs > testing > internationalization
  • 4.
    Project setup $ revelnew myapp $ revel run myapp . ├── app │ ├── controllers │ ├── init.go │ ├── routes │ ├── tmp │ └── views ├── conf │ ├── app.conf │ └── routes ├── messages │ └── sample.en ├── public │ ├── css │ ├── img │ └── js ├── README.md ├── test-results │ ├── app.log │ ├── AppTest.passed.html │ └── result.passed └── tests └── apptest.go ~ ~ revel! http://revel.github.io ~ INFO 2015/01/11 17:54:21 revel.go:326: Loaded module testrunner INFO 2015/01/11 17:54:21 revel.go:326: Loaded module static INFO 2015/01/11 17:54:21 run.go:57: Running myapp (myapp) in dev mode INFO 2015/01/11 17:54:21 harness.go:165: Listening on :9000
  • 5.
    Request flow > GoHTTP server -> goroutine! 0. handler -> filter chain Filters (middleware) - processing pipeline
  • 6.
    Request flow > GoHTTP server -> goroutine! 0. handler -> filter chain 1. filters (processing) -> action 2. action (controller) -> result
  • 7.
    Action & Result& Controller A> method on Controller A> is exported A> returns revel.Result R> implements func Apply(*Request, *Response) C> type embeds *revel.Controller C> context of request
  • 8.
    Request flow > GoHTTP server -> goroutine! 0. handler -> filter chain 1. filters (processing) -> action 2. action (controller) -> result 3. handler -> response
  • 9.
    Templates > Go templates >searched by Controller/Action name > case insensitive names > data-binding > additional functions (fields, set etc.) > custom functions
  • 10.
    Session & Flash S>string map (crypto-signed cookie) S> serialize to store S> default lifetime == browser lifetime F> overwritten on each request F> Post/Redirect/Get
  • 11.
    Jobs (module) > modulesare optional > asynchronous > outside main routine > event-driven (user <action>, on startup, scheduled) /@jobs (watch interactively)
  • 12.
    Testing (module) > run /@tests(interactive) OR $ revel test myapp > type embeds revel.TestSuite > No fixtures, test loggers
  • 13.
    Summing-up > comprehensive > cleardir tree > MVC > jobs > testing > missing ORM (?)
  • 14.
    Links > Web Appsin Go (codewalk) > Revel docs > Web Frameworks in Go