@@ -1275,7 +1275,7 @@ func main() {
12751275  router.StaticFS (" /more_static"  , http.Dir (" my_file_system"  ))
12761276  router.StaticFile (" /favicon.ico"  , " ./resources/favicon.ico"  )
12771277  router.StaticFileFS (" /more_favicon.ico"  , " more_favicon.ico"  , http.Dir (" my_file_system"  ))
1278-    
1278+ 
12791279  //  Listen and serve on 0.0.0.0:8080
12801280  router.Run (" :8080"  )
12811281}
@@ -2114,6 +2114,66 @@ func ListHandler(s *Service) func(ctx *gin.Context) {
21142114}
21152115``` 
21162116
2117+ ### Bind Query with custom unmarshalers  
2118+ 
2119+ Any structure that has custom ` UnmarshalJSON `  or ` UnmarshalText `  or ` UnmarshalBinary `  can be used to parse input as necessary
2120+ 
2121+ ``` go 
2122+ package  main
2123+ 
2124+ import  (
2125+   " fmt" 
2126+   " net/http" 
2127+   " strings" 
2128+ 
2129+   " github.com/gin-gonic/gin" 
2130+ )
2131+ 
2132+ //  Booking contains data binded using custom unmarshaler.
2133+ type  Payload  struct  {
2134+   Email   EmailDetails  ` form:"email"` 
2135+ }
2136+ 
2137+ //  this structure has special json unmarshaller, in order to parse email (as an example) as specific structure
2138+ type  EmailDetails  struct  {
2139+   Name  string 
2140+   Host  string 
2141+ }
2142+ 
2143+ func  (o  *EmailDetails ) UnmarshalJSON  (data  []byte ) error  {
2144+   elems  :=  strings.Split (string (data), " @"  )
2145+   if  len (elems) != 2  {
2146+     return  fmt.Errorf (" cannot parse %q  as email"  , string (data))
2147+   }
2148+   o.Name  = elems[0 ]
2149+   o.Host  = elems[1 ]
2150+   return  nil 
2151+ }
2152+ func  main () {
2153+   route  :=  gin.Default ()
2154+ 
2155+   route.GET (" /email"  , getEmail)
2156+   route.Run (" :8085"  )
2157+ }
2158+ 
2159+ func  getEmail (c  *gin .Context ) {
2160+   var  p  Payload
2161+   if  err  :=  c.ShouldBindQuery (&p); err == nil  {
2162+     c.JSON (http.StatusOK , gin.H {" message"  : " Email information is correct"  })
2163+   } else  {
2164+     c.JSON (http.StatusBadRequest , gin.H {" error"  : err.Error ()})
2165+   }
2166+ }
2167+ ``` 
2168+ 
2169+ ``` console 
2170+ $ 
curl " localhost:8085/[email protected] "  2171+ {"message":"Email information is correct"} 
2172+ 
2173+ $ curl " localhost:8085/email?email=test-something-else"  
2174+ {"error":"cannot parse \"test-something-else\" as email"} 
2175+ ``` 
2176+ 
21172177### http2 server push  
21182178
21192179http.Pusher is supported only ** go1.8+** . See the [ golang blog] ( https://blog.golang.org/h2push )  for detail information.
@@ -2247,7 +2307,7 @@ or network CIDRs from where clients which their request headers related to clien
22472307IP can be trusted. They can be IPv4 addresses, IPv4 CIDRs, IPv6 addresses or
22482308IPv6 CIDRs.
22492309
2250- ** Attention:**  Gin trust all proxies by default if you don't specify a trusted  
2310+ ** Attention:**  Gin trust all proxies by default if you don't specify a trusted
22512311proxy using the function above, ** this is NOT safe** . At the same time, if you don't
22522312use any proxy, you can disable this feature by using ` Engine.SetTrustedProxies(nil) ` ,
22532313then ` Context.ClientIP() `  will return the remote address directly to avoid some
@@ -2277,7 +2337,7 @@ func main() {
22772337``` 
22782338
22792339** Notice:**  If you are using a CDN service, you can set the ` Engine.TrustedPlatform ` 
2280- to skip TrustedProxies check, it has a higher priority than TrustedProxies.  
2340+ to skip TrustedProxies check, it has a higher priority than TrustedProxies.
22812341Look at the example below:
22822342
22832343``` go 
0 commit comments