-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
44 lines (34 loc) · 1.04 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package main
import (
"net/http"
"github.com/kataras/iris/v12"
)
func main() {
app := iris.New()
// Method: GET
// Resource http://localhost:8080
app.Handle("GET", "/", func(ctx iris.Context) {
ctx.HTML("<html><body style='background-color:white;'><h1 style='color:black;'>Welcome to Sample Go Web App</h1></body></html>")
})
// 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/mypath
app.Get("/mypath", func(ctx iris.Context) {
ctx.Writef("Hello from %s", ctx.Path())
})
// Method: GET
// Resource: http://localhost:8080/hello
app.Get("/hello", func(ctx iris.Context) {
ctx.JSON(iris.Map{"message": "Hello World!"})
})
// Any custom fields here. Handler and ErrorLog are set to the server automatically
srv := &http.Server{Addr: ":8080"}
// http://localhost:8080/
// http://localhost:8080/mypath
app.Run(iris.Server(srv)) // same as app.Listen(":8080")
}