@@ -103,7 +103,7 @@ import "net/http"
103103```
104104
105105## Quick start
106-
106+
107107``` sh
108108# assume the following codes in example.go file
109109$ cat example.go
@@ -588,44 +588,44 @@ func main() {
588588::1 - [Fri, 07 Dec 2018 17:04:38 JST] "GET /ping HTTP/1.1 200 122.767µs "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.80 Safari/537.36" "
589589```
590590
591- ### Controlling Log output coloring
591+ ### Controlling Log output coloring
592592
593593By default, logs output on console should be colorized depending on the detected TTY.
594594
595- Never colorize logs:
595+ Never colorize logs:
596596
597597``` go
598598func main () {
599599 // Disable log's color
600600 gin.DisableConsoleColor ()
601-
601+
602602 // Creates a gin router with default middleware:
603603 // logger and recovery (crash-free) middleware
604604 router := gin.Default ()
605-
605+
606606 router.GET (" /ping" , func (c *gin.Context ) {
607607 c.String (200 , " pong" )
608608 })
609-
609+
610610 router.Run (" :8080" )
611611}
612612```
613613
614- Always colorize logs:
614+ Always colorize logs:
615615
616616``` go
617617func main () {
618618 // Force log's color
619619 gin.ForceConsoleColor ()
620-
620+
621621 // Creates a gin router with default middleware:
622622 // logger and recovery (crash-free) middleware
623623 router := gin.Default ()
624-
624+
625625 router.GET (" /ping" , func (c *gin.Context ) {
626626 c.String (200 , " pong" )
627627 })
628-
628+
629629 router.Run (" :8080" )
630630}
631631```
@@ -667,12 +667,12 @@ func main() {
667667 c.JSON (http.StatusBadRequest , gin.H {" error" : err.Error ()})
668668 return
669669 }
670-
670+
671671 if json.User != " manu" || json.Password != " 123" {
672672 c.JSON (http.StatusUnauthorized , gin.H {" status" : " unauthorized" })
673673 return
674- }
675-
674+ }
675+
676676 c.JSON (http.StatusOK , gin.H {" status" : " you are logged in" })
677677 })
678678
@@ -688,12 +688,12 @@ func main() {
688688 c.JSON (http.StatusBadRequest , gin.H {" error" : err.Error ()})
689689 return
690690 }
691-
691+
692692 if xml.User != " manu" || xml.Password != " 123" {
693693 c.JSON (http.StatusUnauthorized , gin.H {" status" : " unauthorized" })
694694 return
695- }
696-
695+ }
696+
697697 c.JSON (http.StatusOK , gin.H {" status" : " you are logged in" })
698698 })
699699
@@ -705,12 +705,12 @@ func main() {
705705 c.JSON (http.StatusBadRequest , gin.H {" error" : err.Error ()})
706706 return
707707 }
708-
708+
709709 if form.User != " manu" || form.Password != " 123" {
710710 c.JSON (http.StatusUnauthorized , gin.H {" status" : " unauthorized" })
711711 return
712- }
713-
712+ }
713+
714714 c.JSON (http.StatusOK , gin.H {" status" : " you are logged in" })
715715 })
716716
@@ -807,7 +807,7 @@ $ curl "localhost:8085/bookable?check_in=2030-03-10&check_out=2030-03-09"
807807{"error":"Key: 'Booking.CheckOut' Error:Field validation for 'CheckOut' failed on the 'gtfield' tag"}
808808
809809$ curl " localhost:8085/bookable?check_in=2000-03-09&check_out=2000-03-10"
810- {"error":"Key: 'Booking.CheckIn' Error:Field validation for 'CheckIn' failed on the 'bookabledate' tag"}%
810+ {"error":"Key: 'Booking.CheckIn' Error:Field validation for 'CheckIn' failed on the 'bookabledate' tag"}%
811811```
812812
813813[ Struct level validations] ( https://github.com/go-playground/validator/releases/tag/v8.7 ) can also be registered this way.
@@ -1145,7 +1145,7 @@ func main() {
11451145 data := gin.H {
11461146 " foo" : " bar" ,
11471147 }
1148-
1148+
11491149 // callback is x
11501150 // Will output : x({\"foo\":\"bar\"})
11511151 c.JSONP (http.StatusOK , data)
@@ -1190,21 +1190,21 @@ This feature is unavailable in Go 1.6 and lower.
11901190``` go
11911191func main () {
11921192 r := gin.Default ()
1193-
1193+
11941194 // Serves unicode entities
11951195 r.GET (" /json" , func (c *gin.Context ) {
11961196 c.JSON (200 , gin.H {
11971197 " html" : " <b>Hello, world!</b>" ,
11981198 })
11991199 })
1200-
1200+
12011201 // Serves literal characters
12021202 r.GET (" /purejson" , func (c *gin.Context ) {
12031203 c.PureJSON (200 , gin.H {
12041204 " html" : " <b>Hello, world!</b>" ,
12051205 })
12061206 })
1207-
1207+
12081208 // listen and serve on 0.0.0.0:8080
12091209 r.Run (" :8080" )
12101210}
@@ -1812,11 +1812,11 @@ func main() {
18121812 // the request it is currently handling
18131813 ctx , cancel := context.WithTimeout (context.Background (), 5 *time.Second )
18141814 defer cancel ()
1815-
1815+
18161816 if err := srv.Shutdown (ctx); err != nil {
18171817 log.Fatal (" Server forced to shutdown:" , err)
18181818 }
1819-
1819+
18201820 log.Println (" Server exiting" )
18211821}
18221822```
0 commit comments