Merge remote-tracking branch 'upstream/master' into remove-go1.6

This commit is contained in:
thinkerou 2019-03-03 12:02:23 +08:00
commit 7d58ced738
3 changed files with 15 additions and 13 deletions

View File

@ -211,6 +211,8 @@ $ go build -tags=jsoniter .
## API Examples
You can find a number of ready-to-run examples at [Gin examples repository](https://github.com/gin-gonic/examples).
### Using GET, POST, PUT, PATCH, DELETE and OPTIONS
```go
@ -359,7 +361,7 @@ ids: map[b:hello a:1234], names: map[second:tianou first:thinkerou]
#### Single file
References issue [#774](https://github.com/gin-gonic/gin/issues/774) and detail [example code](examples/upload-file/single).
References issue [#774](https://github.com/gin-gonic/gin/issues/774) and detail [example code](https://github.com/gin-gonic/examples/tree/master/upload-file/single).
`file.Filename` **SHOULD NOT** be trusted. See [`Content-Disposition` on MDN](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition#Directives) and [#1693](https://github.com/gin-gonic/gin/issues/1693)
@ -394,7 +396,7 @@ curl -X POST http://localhost:8080/upload \
#### Multiple files
See the detail [example code](examples/upload-file/multiple).
See the detail [example code](https://github.com/gin-gonic/examples/tree/master/upload-file/multiple).
```go
func main() {
@ -726,7 +728,7 @@ When running the above example using the above the `curl` command, it returns er
### Custom Validators
It is also possible to register custom validators. See the [example code](examples/custom-validation/server.go).
It is also possible to register custom validators. See the [example code](https://github.com/gin-gonic/examples/tree/master/custom-validation/server.go).
```go
package main
@ -790,7 +792,7 @@ $ curl "localhost:8085/bookable?check_in=2018-03-08&check_out=2018-03-09"
```
[Struct level validations](https://github.com/go-playground/validator/releases/tag/v8.7) can also be registered this way.
See the [struct-lvl-validation example](examples/struct-lvl-validations) to learn more.
See the [struct-lvl-validation example](https://github.com/gin-gonic/examples/tree/master/struct-lvl-validations) to learn more.
### Only Bind Query String
@ -1279,7 +1281,7 @@ You may use custom delims
#### Custom Template Funcs
See the detail [example code](examples/template).
See the detail [example code](https://github.com/gin-gonic/examples/tree/master/template).
main.go
@ -1653,7 +1655,7 @@ An alternative to endless:
* [graceful](https://github.com/tylerb/graceful): Graceful is a Go package enabling graceful shutdown of an http.Handler server.
* [grace](https://github.com/facebookgo/grace): Graceful restart & zero downtime deploy for Go servers.
If you are using Go 1.8, you may not need to use this library! Consider using http.Server's built-in [Shutdown()](https://golang.org/pkg/net/http/#Server.Shutdown) method for graceful shutdowns. See the full [graceful-shutdown](./examples/graceful-shutdown) example with gin.
If you are using Go 1.8, you may not need to use this library! Consider using http.Server's built-in [Shutdown()](https://golang.org/pkg/net/http/#Server.Shutdown) method for graceful shutdowns. See the full [graceful-shutdown](https://github.com/gin-gonic/examples/tree/master/graceful-shutdown) example with gin.
```go
package main
@ -1755,7 +1757,7 @@ func loadTemplate() (*template.Template, error) {
}
```
See a complete example in the `examples/assets-in-binary` directory.
See a complete example in the `https://github.com/gin-gonic/examples/tree/master/assets-in-binary` directory.
### Bind form-data request with custom struct
@ -2077,7 +2079,6 @@ func TestPingRoute(t *testing.T) {
Awesome project lists using [Gin](https://github.com/gin-gonic/gin) web framework.
* [drone](https://github.com/drone/drone): Drone is a Continuous Delivery platform built on Docker, written in Go.
* [gorush](https://github.com/appleboy/gorush): A push notification server written in Go.
* [fnproject](https://github.com/fnproject/fn): The container native, cloud agnostic serverless platform.
* [photoprism](https://github.com/photoprism/photoprism): Personal photo management powered by Go and Google TensorFlow.

View File

@ -891,19 +891,20 @@ func (c *Context) SSEvent(name string, message interface{}) {
})
}
// Stream sends a streaming response.
func (c *Context) Stream(step func(w io.Writer) bool) {
// Stream sends a streaming response and returns a boolean
// indicates "Is client disconnected in middle of stream"
func (c *Context) Stream(step func(w io.Writer) bool) bool {
w := c.Writer
clientGone := w.CloseNotify()
for {
select {
case <-clientGone:
return
return true
default:
keepOpen := step(w)
w.Flush()
if !keepOpen {
return
return false
}
}
}

View File

@ -1,3 +1,3 @@
# Gin Examples
## TODO
⚠️ **NOTICE:** All gin examples has moved as alone repository to [here](https://github.com/gin-gonic/examples).