"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "README.md" between
gin-1.7.6.tar.gz and gin-1.7.7.tar.gz

About: Gin is a HTTP web framework written in Go (Golang). It features a Martini-like API (with much better performance).

README.md  (gin-1.7.6):README.md  (gin-1.7.7)
skipping to change at line 79 skipping to change at line 79
- [Run multiple service using Gin](#run-multiple-service-using-gin) - [Run multiple service using Gin](#run-multiple-service-using-gin)
- [Graceful shutdown or restart](#graceful-shutdown-or-restart) - [Graceful shutdown or restart](#graceful-shutdown-or-restart)
- [Third-party packages](#third-party-packages) - [Third-party packages](#third-party-packages)
- [Manually](#manually) - [Manually](#manually)
- [Build a single binary with templates](#build-a-single-binary-with-templat es) - [Build a single binary with templates](#build-a-single-binary-with-templat es)
- [Bind form-data request with custom struct](#bind-form-data-request-with-c ustom-struct) - [Bind form-data request with custom struct](#bind-form-data-request-with-c ustom-struct)
- [Try to bind body into different structs](#try-to-bind-body-into-different -structs) - [Try to bind body into different structs](#try-to-bind-body-into-different -structs)
- [http2 server push](#http2-server-push) - [http2 server push](#http2-server-push)
- [Define format for the log of routes](#define-format-for-the-log-of-routes ) - [Define format for the log of routes](#define-format-for-the-log-of-routes )
- [Set and get a cookie](#set-and-get-a-cookie) - [Set and get a cookie](#set-and-get-a-cookie)
- [Don't trust all proxies](#don't-trust-all-proxies)
- [Testing](#testing) - [Testing](#testing)
- [Users](#users) - [Users](#users)
## Installation ## Installation
To install Gin package, you need to install Go and set your Go workspace first. To install Gin package, you need to install Go and set your Go workspace first.
1. The first need [Go](https://golang.org/) installed (**version 1.12+ is requir ed**), then you can use the below Go command to install Gin. 1. The first need [Go](https://golang.org/) installed (**version 1.13+ is requir ed**), then you can use the below Go command to install Gin.
```sh ```sh
$ go get -u github.com/gin-gonic/gin $ go get -u github.com/gin-gonic/gin
``` ```
2. Import it in your code: 2. Import it in your code:
```go ```go
import "github.com/gin-gonic/gin" import "github.com/gin-gonic/gin"
``` ```
skipping to change at line 2130 skipping to change at line 2131
router.Run() router.Run()
} }
``` ```
## Don't trust all proxies ## Don't trust all proxies
Gin lets you specify which headers to hold the real client IP (if any), Gin lets you specify which headers to hold the real client IP (if any),
as well as specifying which proxies (or direct clients) you trust to as well as specifying which proxies (or direct clients) you trust to
specify one of these headers. specify one of these headers.
The `TrustedProxies` slice on your `gin.Engine` specifes network addresses or Use function `SetTrustedProxies()` on your `gin.Engine` to specify network addre
network CIDRs from where clients which their request headers related to client sses
or network CIDRs from where clients which their request headers related to clien
t
IP can be trusted. They can be IPv4 addresses, IPv4 CIDRs, IPv6 addresses or IP can be trusted. They can be IPv4 addresses, IPv4 CIDRs, IPv6 addresses or
IPv6 CIDRs. IPv6 CIDRs.
**Attention:** Gin trust all proxies by default if you don't specify a trusted
proxy using the function above, **this is NOT safe**. At the same time, if you d
on't
use any proxy, you can disable this feature by using `Engine.SetTrustedProxies(n
il)`,
then `Context.ClientIP()` will return the remote address directly to avoid some
unnecessary computation.
```go ```go
import ( import (
"fmt" "fmt"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )
func main() { func main() {
router := gin.Default() router := gin.Default()
router.TrustedProxies = []string{"192.168.1.2"} router.SetTrustedProxies([]string{"192.168.1.2"})
router.GET("/", func(c *gin.Context) { router.GET("/", func(c *gin.Context) {
// If the client is 192.168.1.2, use the X-Forwarded-For // If the client is 192.168.1.2, use the X-Forwarded-For
// header to deduce the original client IP from the trust- // header to deduce the original client IP from the trust-
// worthy parts of that header. // worthy parts of that header.
// Otherwise, simply return the direct client IP // Otherwise, simply return the direct client IP
fmt.Printf("ClientIP: %s\n", c.ClientIP()) fmt.Printf("ClientIP: %s\n", c.ClientIP())
}) })
router.Run() router.Run()
} }
``` ```
**Notice:** If you are using a CDN service, you can set the `Engine.TrustedPlatf
orm`
to skip TrustedProxies check, it has a higher priority than TrustedProxies.
Look at the example below:
```go
import (
"fmt"
"github.com/gin-gonic/gin"
)
func main() {
router := gin.Default()
// Use predefined header gin.PlatformXXX
router.TrustedPlatform = gin.PlatformGoogleAppEngine
// Or set your own trusted request header for another trusted proxy servi
ce
// Don't set it to any suspect request header, it's unsafe
router.TrustedPlatform = "X-CDN-IP"
router.GET("/", func(c *gin.Context) {
// If you set TrustedPlatform, ClientIP() will resolve the
// corresponding header and return IP directly
fmt.Printf("ClientIP: %s\n", c.ClientIP())
})
router.Run()
}
```
## Testing ## Testing
The `net/http/httptest` package is preferable way for HTTP testing. The `net/http/httptest` package is preferable way for HTTP testing.
```go ```go
package main package main
func setupRouter() *gin.Engine { func setupRouter() *gin.Engine {
r := gin.Default() r := gin.Default()
r.GET("/ping", func(c *gin.Context) { r.GET("/ping", func(c *gin.Context) {
 End of changes. 6 change blocks. 
4 lines changed or deleted 45 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)