chore: Deleted spaces (#2622)
This commit is contained in:
committed by
GitHub
parent
b01605bb5b
commit
e899771392
@@ -103,7 +103,7 @@ import "net/http"
|
||||
```
|
||||
|
||||
## Quick start
|
||||
|
||||
|
||||
```sh
|
||||
# assume the following codes in example.go file
|
||||
$ cat example.go
|
||||
@@ -588,44 +588,44 @@ func main() {
|
||||
::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" "
|
||||
```
|
||||
|
||||
### Controlling Log output coloring
|
||||
### Controlling Log output coloring
|
||||
|
||||
By default, logs output on console should be colorized depending on the detected TTY.
|
||||
|
||||
Never colorize logs:
|
||||
Never colorize logs:
|
||||
|
||||
```go
|
||||
func main() {
|
||||
// Disable log's color
|
||||
gin.DisableConsoleColor()
|
||||
|
||||
|
||||
// Creates a gin router with default middleware:
|
||||
// logger and recovery (crash-free) middleware
|
||||
router := gin.Default()
|
||||
|
||||
|
||||
router.GET("/ping", func(c *gin.Context) {
|
||||
c.String(200, "pong")
|
||||
})
|
||||
|
||||
|
||||
router.Run(":8080")
|
||||
}
|
||||
```
|
||||
|
||||
Always colorize logs:
|
||||
Always colorize logs:
|
||||
|
||||
```go
|
||||
func main() {
|
||||
// Force log's color
|
||||
gin.ForceConsoleColor()
|
||||
|
||||
|
||||
// Creates a gin router with default middleware:
|
||||
// logger and recovery (crash-free) middleware
|
||||
router := gin.Default()
|
||||
|
||||
|
||||
router.GET("/ping", func(c *gin.Context) {
|
||||
c.String(200, "pong")
|
||||
})
|
||||
|
||||
|
||||
router.Run(":8080")
|
||||
}
|
||||
```
|
||||
@@ -667,12 +667,12 @@ func main() {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
if json.User != "manu" || json.Password != "123" {
|
||||
c.JSON(http.StatusUnauthorized, gin.H{"status": "unauthorized"})
|
||||
return
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{"status": "you are logged in"})
|
||||
})
|
||||
|
||||
@@ -688,12 +688,12 @@ func main() {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
if xml.User != "manu" || xml.Password != "123" {
|
||||
c.JSON(http.StatusUnauthorized, gin.H{"status": "unauthorized"})
|
||||
return
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{"status": "you are logged in"})
|
||||
})
|
||||
|
||||
@@ -705,12 +705,12 @@ func main() {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
if form.User != "manu" || form.Password != "123" {
|
||||
c.JSON(http.StatusUnauthorized, gin.H{"status": "unauthorized"})
|
||||
return
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{"status": "you are logged in"})
|
||||
})
|
||||
|
||||
@@ -807,7 +807,7 @@ $ curl "localhost:8085/bookable?check_in=2030-03-10&check_out=2030-03-09"
|
||||
{"error":"Key: 'Booking.CheckOut' Error:Field validation for 'CheckOut' failed on the 'gtfield' tag"}
|
||||
|
||||
$ curl "localhost:8085/bookable?check_in=2000-03-09&check_out=2000-03-10"
|
||||
{"error":"Key: 'Booking.CheckIn' Error:Field validation for 'CheckIn' failed on the 'bookabledate' tag"}%
|
||||
{"error":"Key: 'Booking.CheckIn' Error:Field validation for 'CheckIn' failed on the 'bookabledate' tag"}%
|
||||
```
|
||||
|
||||
[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() {
|
||||
data := gin.H{
|
||||
"foo": "bar",
|
||||
}
|
||||
|
||||
|
||||
//callback is x
|
||||
// Will output : x({\"foo\":\"bar\"})
|
||||
c.JSONP(http.StatusOK, data)
|
||||
@@ -1190,21 +1190,21 @@ This feature is unavailable in Go 1.6 and lower.
|
||||
```go
|
||||
func main() {
|
||||
r := gin.Default()
|
||||
|
||||
|
||||
// Serves unicode entities
|
||||
r.GET("/json", func(c *gin.Context) {
|
||||
c.JSON(200, gin.H{
|
||||
"html": "<b>Hello, world!</b>",
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
// Serves literal characters
|
||||
r.GET("/purejson", func(c *gin.Context) {
|
||||
c.PureJSON(200, gin.H{
|
||||
"html": "<b>Hello, world!</b>",
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
// listen and serve on 0.0.0.0:8080
|
||||
r.Run(":8080")
|
||||
}
|
||||
@@ -1812,11 +1812,11 @@ func main() {
|
||||
// the request it is currently handling
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
defer cancel()
|
||||
|
||||
|
||||
if err := srv.Shutdown(ctx); err != nil {
|
||||
log.Fatal("Server forced to shutdown:", err)
|
||||
}
|
||||
|
||||
|
||||
log.Println("Server exiting")
|
||||
}
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user