File tree Expand file tree Collapse file tree 1 file changed +38
-1
lines changed Expand file tree Collapse file tree 1 file changed +38
-1
lines changed Original file line number Diff line number Diff line change @@ -70,7 +70,44 @@ func main() {
7070```
7171
7272- middleware
73- ```
73+ ``` golang
74+ package main
75+
76+ import (
77+ " log"
78+
79+ " github.com/godzillaframework/godzilla"
80+ )
81+
82+ func main () {
83+
84+ gz := godzilla.New ()
85+
86+ logMiddleware := func (ctx godzilla.Context ) {
87+ log.Printf (" log message!" )
88+
89+ ctx.Next ()
90+ }
91+
92+ unAuthorizedMiddleware := func (ctx godzilla.Context ) {
93+ ctx.Status (godzilla.StatusUnauthorized ).SendString (" You are unauthorized to access this page!" )
94+ }
95+
96+ gz.Use (logMiddleware)
97+
98+ gz.Get (" /hello" , func (ctx godzilla.Context ) {
99+ ctx.SendString (" Hello World!" )
100+ })
101+
102+ gz.Get (" /protected" , unAuthorizedMiddleware, func (ctx godzilla.Context ) {
103+ ctx.SendString (" You accessed a protected page" )
104+ })
105+
106+ gz.Static (" /main" , " ./index.html" )
107+
108+ gz.Start (" :8080" )
109+ }
110+
74111```
75112
76113- for more tutorials visit the [ docs] ( https://github.com/godzillaframework/godzilla/blob/master/docs/learngodzilla.md )
You can’t perform that action at this time.
0 commit comments