-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
31 lines (26 loc) · 818 Bytes
/
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
package main
import (
"github.com/toucham/gotitan/server"
"github.com/toucham/gotitan/server/msg"
)
func main() {
PORT := "8080"
HOST := "127.0.0.1"
app := server.Init(HOST, PORT)
// add middlware
// app.AddReqMiddlware(func(req *server.HttpRequest) {
// }, server.MiddlwareOptions{})
// add routing
indexAction := func(req msg.Request) msg.Response {
res := msg.CreateHttpResponse(msg.StatusOk)
res.SetBody("<div> <h1> Welcome to the index page </h1> </div>", "text/html; charset=utf-8")
return res
}
app.AddRoute(msg.HTTP_GET, "/", func(req msg.Request) msg.Response {
res := msg.CreateHttpResponse(msg.StatusOk)
res.SetBody("<div> <h1> Welcome to the first page </h1> </div>", "text/html; charset=utf-8")
return res
})
app.AddRoute(msg.HTTP_GET, "/index", indexAction)
app.Start()
}