Improve "Upload file" example, Fix MD typos

This commit is contained in:
Javier Provecho Fernandez 2017-01-03 17:04:29 +01:00 committed by GitHub
parent 17af53a565
commit 050937dab8

View File

@ -111,7 +111,7 @@ BenchmarkZeus_GithubAll | 2000 | 944234 | 300688 | 2648
## API Examples
#### Using GET, POST, PUT, PATCH, DELETE and OPTIONS
### Using GET, POST, PUT, PATCH, DELETE and OPTIONS
```go
func main() {
@ -137,7 +137,7 @@ func main() {
}
```
#### Parameters in path
### Parameters in path
```go
func main() {
@ -162,7 +162,7 @@ func main() {
}
```
#### Querystring parameters
### Querystring parameters
```go
func main() {
router := gin.Default()
@ -229,9 +229,9 @@ func main() {
id: 1234; page: 1; name: manu; message: this_is_great
```
### upload file
### Upload files
#### upload single file
#### Single file
References issue [#774](https://github.com/gin-gonic/gin/issues/774) and detail [example code](examples/upload-file/single).
@ -243,13 +243,13 @@ func main() {
file, _ := c.FormFile("file")
log.Println(file.Filename)
c.String(http.StatusOK, "Uploaded...")
c.String(http.StatusOK, fmt.Printf("'%s' uploaded!", file.Filename))
})
router.Run(":8080")
}
```
curl command:
How to `curl`:
```bash
curl -X POST http://localhost:8080/upload \
@ -257,7 +257,7 @@ curl -X POST http://localhost:8080/upload \
-H "Content-Type: multipart/form-data"
```
#### upload multiple files
#### Multiple files
See the detail [example code](examples/upload-file/multiple).
@ -272,13 +272,13 @@ func main() {
for _, file := range files {
log.Println(file.Filename)
}
c.String(http.StatusOK, "Uploaded...")
c.String(http.StatusOK, fmt.Printf("%d files uploaded!", len(files)))
})
router.Run(":8080")
}
```
curl command:
How to `curl`:
```bash
curl -X POST http://localhost:8080/upload \
@ -287,7 +287,7 @@ curl -X POST http://localhost:8080/upload \
-H "Content-Type: multipart/form-data"
```
#### Grouping routes
### Grouping routes
```go
func main() {
@ -314,7 +314,7 @@ func main() {
```
#### Blank Gin without middleware by default
### Blank Gin without middleware by default
Use
@ -328,7 +328,7 @@ r := gin.Default()
```
#### Using middleware
### Using middleware
```go
func main() {
// Creates a router without any middleware by default
@ -363,7 +363,7 @@ func main() {
}
```
#### Model binding and validation
### Model binding and validation
To bind a request body into a type, use model binding. We currently support binding of JSON, XML and standard form values (foo=bar&boo=baz).
@ -413,7 +413,7 @@ func main() {
}
```
#### Bind Query String
### Bind Query String
See the [detail information](https://github.com/gin-gonic/gin/issues/742#issuecomment-264681292).
@ -489,7 +489,7 @@ $ curl -v --form user=user --form password=password http://localhost:8080/login
```
#### XML, JSON and YAML rendering
### XML, JSON and YAML rendering
```go
func main() {
@ -528,7 +528,7 @@ func main() {
}
```
####Serving static files
### Serving static files
```go
func main() {
@ -542,7 +542,7 @@ func main() {
}
```
####HTML rendering
### HTML rendering
Using LoadHTMLGlob() or LoadHTMLFiles()
@ -622,7 +622,7 @@ func main() {
```
#### Redirects
### Redirects
Issuing a HTTP redirect is easy:
@ -634,7 +634,7 @@ r.GET("/test", func(c *gin.Context) {
Both internal and external locations are supported.
#### Custom Middleware
### Custom Middleware
```go
func Logger() gin.HandlerFunc {
@ -674,7 +674,7 @@ func main() {
}
```
#### Using BasicAuth() middleware
### Using BasicAuth() middleware
```go
// simulate some private data
var secrets = gin.H{
@ -713,7 +713,7 @@ func main() {
```
#### Goroutines inside a middleware
### Goroutines inside a middleware
When starting inside a middleware or handler, you **SHOULD NOT** use the original context inside it, you have to use a read-only copy.
```go
@ -745,7 +745,7 @@ func main() {
}
```
#### Custom HTTP configuration
### Custom HTTP configuration
Use `http.ListenAndServe()` directly, like this:
@ -772,7 +772,7 @@ func main() {
}
```
#### Graceful restart or stop
### Graceful restart or stop
Do you want to graceful restart or stop your web server?
There are some ways this can be done.
@ -803,7 +803,7 @@ An alternative to endless:
- You should add/modify tests to cover your proposed code changes.
- If your pull request contains a new feature, please document it on the README.
## Example
## Users
Awesome project lists using [Gin](https://github.com/gin-gonic/gin) web framework.