-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
66 lines (47 loc) · 1.21 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/* making this file exec */
package main
import (
"log"
"github.com/godzillaframework/godzilla"
)
/* strucutre for json */
type User struct {
Username string
Password string
}
/* main func */
func main() {
/* new godzilla app */
gz := godzilla.New()
gz.Get("/index", func(ctx godzilla.Context) {
ctx.SendString("Hey EveryOne")
})
/* params */
gz.Get("/param/:param", func(ctx godzilla.Context) {
ctx.SendString(ctx.Param("param"))
})
/* godzilla framework supports hosting static files */
gz.Static("/static", "./imgs")
gz.Static("/main", "./hello.html")
/* start of json examples */
gz.Get("/jsontest", func(ctx godzilla.Context) {
var usertable = User{Username: "UserOne", Password: "PasswordOne"}
ctx.SendJSON(&usertable)
})
/* end */
/* middlewares */
/* logger */
logMiddleware := func(ctx godzilla.Context) {
log.Printf("log!!")
ctx.Next()
}
gz.Use(logMiddleware)
/* unauthorized */
unAuthorizedMiddleware := func(ctx godzilla.Context) {
ctx.Status(godzilla.StatusUnauthorized).SendString("Hey get out of here!!")
}
gz.Get("/unauthorized", unAuthorizedMiddleware, func(ctx godzilla.Context) {
ctx.SendString("UNAUTHORIZED PAGE ACCESSED!!!")
})
gz.Start(":8080")
}