1
0
mirror of https://github.com/kataras/iris.git synced 2026-01-08 20:41:57 +00:00

Add a simple Caddy+Iris tutorial 👍

Former-commit-id: 8761afce72aa35b91c9b5a958f1cafc027aabddd
This commit is contained in:
kataras
2017-08-28 12:26:45 +03:00
parent e2600450f7
commit 674622f814
7 changed files with 194 additions and 49 deletions

View File

@@ -56,11 +56,10 @@ Iris may have reached version 8, but we're not stopping there. We have many feat
* [Sessions](_examples/#sessions)
* [Websockets](_examples/#websockets)
* [Miscellaneous](_examples/#miscellaneous)
* [POC: Convert the medium-sized project "Parrot" from native to Iris](https://github.com/iris-contrib/parrot)
* [Typescript Automation Tools](typescript/#table-of-contents)
* [Tutorial: Online Visitors](_examples/tutorial/online-visitors)
* [Tutorial: URL Shortener using BoltDB](https://medium.com/@kataras/a-url-shortener-service-using-go-iris-and-bolt-4182f0b00ae7)
* [Tutorial: How to turn your Android Device into a fully featured Web Server (**MUST**)](https://twitter.com/ThePracticalDev/status/892022594031017988)
* [POC: Convert the medium-sized project "Parrot" from native to Iris](https://github.com/iris-contrib/parrot)
* [Tutorial: Caddy](_examples/tutorial/caddy)
* [Middleware](middleware/)
* [Dockerize](https://github.com/iris-contrib/cloud-native-go)
* [Community & Support](#-community)
@@ -85,18 +84,6 @@ $ go get -u github.com/kataras/iris
> _iris_ takes advantage of the [vendor directory](https://docs.google.com/document/d/1Bz5-UB7g2uPBdOx-rw5t9MxJwkfpx90cqG9AFL0JAYo) feature. You get truly reproducible builds, as this method guards against upstream renames and deletes.
```html
<!-- file: ./views/hello.html -->
<html>
<head>
<title>Hello Page</title>
</head>
<body>
<h1>{{.message}}</h1>
</body>
</html>
```
```go
// file: main.go
package main
@@ -129,43 +116,19 @@ func main() {
app.Run(iris.Addr(":8080"))
}
```
<details>
<summary>Fan of the MVC Architectural Pattern? Click here</summary>
```go
package main
import "github.com/kataras/iris"
func main() {
app := iris.New()
app.RegisterView(iris.HTML("./views", ".html"))
app.Controller("/", new(Controller))
app.Run(iris.Addr(":8080"))
}
type Controller struct {
iris.Controller
}
// Method: GET
// Resource: http://localhost:8080
func (c *Controller) Get() {
c.Data["message"] = "Hello world!"
c.Tmpl = "hello.html"
}
// Method: GET
// Resource: http://localhost:8080/user/42
func (c *Controller) GetBy(id int64) {
c.Ctx.Writef("User ID: %d", id)
}
```html
<!-- file: ./views/hello.html -->
<html>
<head>
<title>Hello Page</title>
</head>
<body>
<h1>{{.message}}</h1>
</body>
</html>
```
</details>
```sh
$ go run main.go
> Now listening on: http://localhost:8080
@@ -204,6 +167,43 @@ func main() {
</details>
<details>
<summary>Fan of the MVC Architectural Pattern? Click here</summary>
```go
package main
import "github.com/kataras/iris"
func main() {
app := iris.New()
app.RegisterView(iris.HTML("./views", ".html"))
app.Controller("/", new(Controller))
app.Run(iris.Addr(":8080"))
}
type Controller struct {
iris.Controller
}
// Method: GET
// Resource: http://localhost:8080
func (c *Controller) Get() {
c.Data["message"] = "Hello world!"
c.Tmpl = "hello.html"
}
// Method: GET
// Resource: http://localhost:8080/user/42
func (c *Controller) GetUserBy(id int64) {
c.Ctx.Writef("User ID: %d", id)
}
```
</details>
<details>
<summary>Why a new web framework</summary>