iris/_examples/hello-world/main_go19.go
kataras 4f2985cb4e Nothing serious yet, thinking new features with the team, post some to help us!
Former-commit-id: 5741c47230bd2f3b88bf9e943742418be664cfdd
2017-07-30 19:47:50 +03:00

45 lines
1.0 KiB
Go

// +build go1.9
package main
import (
"github.com/kataras/iris"
)
// Same as `main.go` for go1.8+ but it omits the
// `github.com/kataras/iris/context` import path
// because of the type alias feature of go 1.9.
func main() {
// The `iris#Default` adds two built'n handlers
// that can recover from any http-relative panics
// and log the requests to the terminal.
//
// Use `iris#New` instead.
app := iris.Default()
// Method: GET
// Resource: http://localhost:8080/
app.Handle("GET", "/", func(ctx iris.Context) {
ctx.HTML("<b>Hello world!</b>")
})
// same as app.Handle("GET", "/ping", [...])
// Method: GET
// Resource: http://localhost:8080/ping
app.Get("/ping", func(ctx iris.Context) {
ctx.WriteString("pong")
})
// Method: GET
// Resource: http://localhost:8080/hello
app.Get("/hello", func(ctx iris.Context) {
ctx.JSON(iris.Map{"message": "Hello iris web framework."})
})
// http://localhost:8080
// http://localhost:8080/ping
// http://localhost:8080/hello
app.Run(iris.Addr(":8080"))
}