├── app ├── app.go ├── basic.go ├── readme.md ├── readme_screen.png └── templates └── article.html /app: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gauravtiwari/go_iris_app/541108507c38ef2955b7cce663925cc2aec2ac70/app -------------------------------------------------------------------------------- /app.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/kataras/iris" 5 | ) 6 | 7 | // Serve using a host:port form. 8 | var addr = iris.Addr("localhost:3000") 9 | 10 | func main() { 11 | app := iris.New() 12 | 13 | // Register the templates/**.html as django and reload them on each request 14 | // so changes can be reflected, set to false on production. 15 | app.RegisterView(iris.Django("./templates", ".html").Reload(true)) 16 | 17 | // GET: http://localhost:3000 18 | app.Get("/", index) 19 | 20 | // GET: http://localhost:3000/profile/myname/article/42 21 | app.Get("/profile/{name:string}/article/{id:int}", iris.Gzip, article) 22 | 23 | // Now listening on: http://localhost:3000 24 | // Application started. Press CTRL+C to shut down. 25 | app.Run(addr) 26 | } 27 | 28 | func article(ctx iris.Context) { 29 | // retrieve the dynamic path parameters. 30 | var ( 31 | name = ctx.Params().Get("name") 32 | articleID, _ = ctx.Params().GetInt("id") 33 | ) 34 | 35 | // set the template's binded values. 36 | ctx.ViewData("Name", name) 37 | ctx.ViewData("ArticleID", articleID) 38 | 39 | // finally, render the template. 40 | ctx.View("article.html") 41 | } 42 | 43 | func index(ctx iris.Context) { 44 | ctx.JSON(iris.Map{"message": "Hello World"}) 45 | } 46 | -------------------------------------------------------------------------------- /basic.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "log" 6 | "net/http" 7 | ) 8 | 9 | type Hello struct{} 10 | 11 | func (h Hello) ServeHTTP( 12 | w http.ResponseWriter, 13 | r *http.Request) { 14 | fmt.Fprint(w, "Hello!") 15 | } 16 | 17 | func main() { 18 | var h Hello 19 | err := http.ListenAndServe("localhost:4000", h) 20 | if err != nil { 21 | log.Fatal(err) 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # A basic web app built in Iris web framework for Go 2 | 3 | ![overview screen](readme_screen.png) 4 | 5 | ## Getting started 6 | 7 | 1. Install Go (Golang) 8 | * Using [Brew](https://brew.sh/). 9 | * Or by navigating to https://golang.org/dl. 10 | 2. Download & Install [Iris](https://iris-go.com) using go get: `go get -u github.com/kataras/iris` 11 | 3. Clone the repository. 12 | 4. Run the web app: `go run app.go` 13 | 14 | ```bash 15 | $ brew install go 16 | $ go get -u github.com/kataras/iris 17 | $ cd $GOPATH/src/ 18 | $ git clone https://github.com/iris-contrib/go_iris_app.git 19 | $ cd ./go_iris_app 20 | $ go run app.go 21 | ``` 22 | 23 | -------------------------------------------------------------------------------- /readme_screen.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gauravtiwari/go_iris_app/541108507c38ef2955b7cce663925cc2aec2ac70/readme_screen.png -------------------------------------------------------------------------------- /templates/article.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | {{ Name }}'s Article 4 | 5 | 6 |

Hi {{ Name }}!

7 |

8 | The article's ID is: {{ ArticleID }}. 9 |

10 | 11 | 12 | --------------------------------------------------------------------------------