2017-07-10 17:32:42 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2019-10-25 00:27:02 +02:00
|
|
|
"github.com/kataras/iris/v12"
|
2017-08-18 16:09:18 +02:00
|
|
|
|
2019-10-25 00:27:02 +02:00
|
|
|
"github.com/kataras/iris/v12/middleware/logger"
|
|
|
|
"github.com/kataras/iris/v12/middleware/recover"
|
2017-07-10 17:32:42 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2017-07-30 18:47:50 +02:00
|
|
|
app := iris.New()
|
2017-12-30 19:40:52 +01:00
|
|
|
app.Logger().SetLevel("debug")
|
2019-02-23 06:23:10 +01:00
|
|
|
// Optionally, add two builtin handlers
|
2017-07-30 18:47:50 +02:00
|
|
|
// that can recover from any http-relative panics
|
|
|
|
// and log the requests to the terminal.
|
|
|
|
app.Use(recover.New())
|
|
|
|
app.Use(logger.New())
|
2017-07-10 17:32:42 +02:00
|
|
|
|
|
|
|
// Method: GET
|
2017-09-02 13:32:14 +02:00
|
|
|
// Resource: http://localhost:8080
|
2017-08-27 19:35:23 +02:00
|
|
|
app.Handle("GET", "/", func(ctx iris.Context) {
|
2017-09-02 13:32:14 +02:00
|
|
|
ctx.HTML("<h1>Welcome</h1>")
|
2017-07-10 17:32:42 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
// same as app.Handle("GET", "/ping", [...])
|
|
|
|
// Method: GET
|
2017-08-24 14:51:43 +02:00
|
|
|
// Resource: http://localhost:8080/ping
|
2017-08-27 19:35:23 +02:00
|
|
|
app.Get("/ping", func(ctx iris.Context) {
|
2017-07-10 17:32:42 +02:00
|
|
|
ctx.WriteString("pong")
|
|
|
|
})
|
|
|
|
|
|
|
|
// Method: GET
|
|
|
|
// Resource: http://localhost:8080/hello
|
2017-08-27 19:35:23 +02:00
|
|
|
app.Get("/hello", func(ctx iris.Context) {
|
2017-09-02 13:32:14 +02:00
|
|
|
ctx.JSON(iris.Map{"message": "Hello Iris!"})
|
2017-07-10 17:32:42 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
// http://localhost:8080
|
|
|
|
// http://localhost:8080/ping
|
|
|
|
// http://localhost:8080/hello
|
2020-04-28 04:22:58 +02:00
|
|
|
app.Listen(":8080")
|
2017-07-10 17:32:42 +02:00
|
|
|
}
|