Update the README.md

Former-commit-id: f1a4582481f3cc43c5e18ad954ae5f7ae98f4c54
This commit is contained in:
Gerasimos (Makis) Maropoulos 2017-02-23 13:56:59 +02:00
parent 8bae4cea6d
commit 3fbaf037a6
2 changed files with 73 additions and 25 deletions

View File

@ -59,6 +59,7 @@ I'm grateful for all the generous donations. Iris is fully funded by these dona
- [Lex Tang](https://github.com/lexrus) donated 20 EUR at February 22 of 2017 - [Lex Tang](https://github.com/lexrus) donated 20 EUR at February 22 of 2017
> * The name or/and github username link added after donator's approvement via e-mail. > * The name or/and github username link added after donator's approvement via e-mail.
#### Report, so far #### Report, so far

View File

@ -97,10 +97,18 @@ Installation
The only requirement is the [Go Programming Language](https://golang.org/dl/), at least 1.8 The only requirement is the [Go Programming Language](https://golang.org/dl/), at least 1.8
```bash ```sh
$ go get gopkg.in/kataras/iris.v6 $ go get gopkg.in/kataras/iris.v6
``` ```
Documentation
-----------
https://godoc.org/gopkg.in/kataras/iris.v6
#### Getting Started with Go+Iris
http://gopherbook.iris-go.com
Overview Overview
----------- -----------
@ -110,32 +118,42 @@ package main
import ( import (
"gopkg.in/kataras/iris.v6" "gopkg.in/kataras/iris.v6"
"gopkg.in/kataras/iris.v6/adaptors/view" "gopkg.in/kataras/iris.v6/adaptors/cors"
"gopkg.in/kataras/iris.v6/adaptors/httprouter" "gopkg.in/kataras/iris.v6/adaptors/httprouter"
"gopkg.in/kataras/iris.v6/adaptors/view"
) )
func main() { func main() {
// Receives optional iris.Configuration{}, see ./configuration.go
// for more.
app := iris.New() app := iris.New()
app.Adapt(iris.Devlogger()) // adapt a logger which prints all errors to the os.Stdout
app.Adapt(httprouter.New()) // adapt the adaptors/httprouter or adaptors/gorillamux
// 5 template engines are supported out-of-the-box: // Order doesn't matter,
// // You can split it to different .Adapt calls.
// - standard html/template // See ./adaptors folder for more.
// - amber app.Adapt(
// - django // adapt a logger which prints all errors to the os.Stdout
// - handlebars iris.DevLogger(),
// - pug(jade) // adapt the adaptors/httprouter or adaptors/gorillamux
// httprouter.New(),
// Use the html standard engine for all files inside "./views" folder with extension ".html" // 5 template engines are supported out-of-the-box:
templates := view.HTML("./views", ".html") //
app.Adapt(templates) // - standard html/template
// - amber
// - django
// - handlebars
// - pug(jade)
//
// Use the html standard engine for all files inside "./views" folder with extension ".html"
view.HTML("./views", ".html"),
// Cors wrapper to the entire application, allow all origins.
cors.New(cors.Options{AllowedOrigins: []string{"*"}}))
// http://localhost:6200 // http://localhost:6300
// Method: "GET" // Method: "GET"
// Render ./views/index.html // Render ./views/index.html
app.Get("/", func(ctx *iris.Context) { app.Get("/", func(ctx *iris.Context) {
ctx.Render("index.html", nil) ctx.Render("index.html", iris.Map{"Title": "Page Title"}, iris.RenderOptions{"gzip": true})
}) })
// Group routes, optionally: share middleware, template layout and custom http errors. // Group routes, optionally: share middleware, template layout and custom http errors.
@ -143,24 +161,39 @@ func main() {
Layout("layouts/userLayout.html") Layout("layouts/userLayout.html")
{ {
// Fire userNotFoundHandler when Not Found // Fire userNotFoundHandler when Not Found
// inside http://localhost:6200/users/*anything // inside http://localhost:6300/users/*anything
userAPI.OnError(404, userNotFoundHandler) userAPI.OnError(404, userNotFoundHandler)
// http://localhost:6200/users // http://localhost:6300/users
// Method: "GET" // Method: "GET"
userAPI.Get("/", getAllHandler) userAPI.Get("/", getAllHandler)
// http://localhost:6200/users/42 // http://localhost:6300/users/42
// Method: "GET" // Method: "GET"
userAPI.Get("/:id", getByIDHandler) userAPI.Get("/:id", getByIDHandler)
// http://localhost:6200/users // http://localhost:6300/users
// Method: "POST" // Method: "POST"
userAPI.Post("/", saveUserHandler) userAPI.Post("/", saveUserHandler)
} }
// Start the server at 127.0.0.1:6200 // Start the server at 127.0.0.1:6300
app.Listen(":6200") app.Listen(":6300")
}
func userAPIMiddleware(ctx *iris.Context) {
// your code here...
println("Request: " + ctx.Path())
ctx.Next() // go to the next handler(s)
}
func userNotFoundHandler(ctx *iris.Context) {
// your code here...
ctx.HTML(iris.StatusNotFound, "<h1> User page not found </h1>")
}
func getAllHandler(ctx *iris.Context) {
// your code here...
} }
func getByIDHandler(ctx *iris.Context) { func getByIDHandler(ctx *iris.Context) {
@ -179,11 +212,25 @@ func getByIDHandler(ctx *iris.Context) {
// like the iris.Map{"username" : user.Username}. // like the iris.Map{"username" : user.Username}.
ctx.JSON(iris.StatusOK, user) ctx.JSON(iris.StatusOK, user)
} }
func saveUserHandler(ctx *iris.Context) {
// your code here...
}
``` ```
> TIP: Execute `iris run main.go` to enable hot-reload on .go source code changes.
> TIP: Add `templates.Reload(true)` to monitor the template changes. ### Reload on source code changes
```sh
$ go get -u github.com/kataras/rizla
$ cd $GOPATH/src/mywebapp
$ rizla run main.go
```
### Reload templates on each incoming request
```go
app.Adapt(view.HTML("./views", ".html").Reload(true))
```
Documentation Documentation