From 3fbaf037a6de309f7fc6a771c16e44195d637bc4 Mon Sep 17 00:00:00 2001 From: "Gerasimos (Makis) Maropoulos" Date: Thu, 23 Feb 2017 13:56:59 +0200 Subject: [PATCH] Update the README.md Former-commit-id: f1a4582481f3cc43c5e18ad954ae5f7ae98f4c54 --- DONATIONS.md | 1 + README.md | 97 ++++++++++++++++++++++++++++++++++++++-------------- 2 files changed, 73 insertions(+), 25 deletions(-) diff --git a/DONATIONS.md b/DONATIONS.md index f31cbe33..5c4842bf 100644 --- a/DONATIONS.md +++ b/DONATIONS.md @@ -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 + > * The name or/and github username link added after donator's approvement via e-mail. #### Report, so far diff --git a/README.md b/README.md index b438e4d3..23f28f32 100644 --- a/README.md +++ b/README.md @@ -97,10 +97,18 @@ Installation 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 ``` +Documentation +----------- +https://godoc.org/gopkg.in/kataras/iris.v6 + +#### Getting Started with Go+Iris + +http://gopherbook.iris-go.com + Overview ----------- @@ -110,32 +118,42 @@ package main import ( "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/view" ) func main() { + // Receives optional iris.Configuration{}, see ./configuration.go + // for more. 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: - // - // - standard html/template - // - amber - // - django - // - handlebars - // - pug(jade) - // - // Use the html standard engine for all files inside "./views" folder with extension ".html" - templates := view.HTML("./views", ".html") - app.Adapt(templates) + // Order doesn't matter, + // You can split it to different .Adapt calls. + // See ./adaptors folder for more. + app.Adapt( + // adapt a logger which prints all errors to the os.Stdout + iris.DevLogger(), + // adapt the adaptors/httprouter or adaptors/gorillamux + httprouter.New(), + // 5 template engines are supported out-of-the-box: + // + // - 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" // Render ./views/index.html 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. @@ -143,24 +161,39 @@ func main() { Layout("layouts/userLayout.html") { // Fire userNotFoundHandler when Not Found - // inside http://localhost:6200/users/*anything + // inside http://localhost:6300/users/*anything userAPI.OnError(404, userNotFoundHandler) - // http://localhost:6200/users + // http://localhost:6300/users // Method: "GET" userAPI.Get("/", getAllHandler) - // http://localhost:6200/users/42 + // http://localhost:6300/users/42 // Method: "GET" userAPI.Get("/:id", getByIDHandler) - // http://localhost:6200/users + // http://localhost:6300/users // Method: "POST" userAPI.Post("/", saveUserHandler) } - // Start the server at 127.0.0.1:6200 - app.Listen(":6200") + // Start the server at 127.0.0.1:6300 + 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, "

User page not found

") +} + +func getAllHandler(ctx *iris.Context) { + // your code here... } func getByIDHandler(ctx *iris.Context) { @@ -179,11 +212,25 @@ func getByIDHandler(ctx *iris.Context) { // like the iris.Map{"username" : user.Username}. 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