mirror of
https://github.com/gin-gonic/gin.git
synced 2025-10-22 01:12:16 +08:00
Merge branch 'master' into new_mapping
This commit is contained in:
commit
9c8c90dc5c
17
README.md
17
README.md
@ -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
|
||||
|
||||
@ -1280,7 +1282,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
|
||||
|
||||
@ -1654,7 +1656,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
|
||||
// +build go1.8
|
||||
@ -1758,7 +1760,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
|
||||
|
||||
@ -2062,7 +2064,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.
|
||||
|
@ -896,19 +896,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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,3 @@
|
||||
# Gin Examples
|
||||
|
||||
## TODO
|
||||
⚠️ **NOTICE:** All gin examples has moved as alone repository to [here](https://github.com/gin-gonic/examples).
|
||||
|
Loading…
x
Reference in New Issue
Block a user