Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update newest doc from gin readme #49

Merged
merged 26 commits into from
Mar 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
9717a02
add npm package
thinkerou Feb 15, 2019
4e2618d
Merge remote-tracking branch 'upstream/master'
thinkerou Feb 15, 2019
3d402f5
Merge remote-tracking branch 'upstream/master'
thinkerou Feb 15, 2019
09f356f
Merge remote-tracking branch 'upstream/master'
thinkerou Feb 15, 2019
b9736e0
Merge remote-tracking branch 'upstream/master'
thinkerou Feb 15, 2019
99565ce
Merge remote-tracking branch 'upstream/master'
thinkerou Feb 15, 2019
bee4e50
Merge remote-tracking branch 'upstream/master'
thinkerou Feb 15, 2019
fea7b98
Merge remote-tracking branch 'upstream/master'
thinkerou Feb 16, 2019
441ee04
Merge remote-tracking branch 'upstream/master'
thinkerou Feb 16, 2019
e491355
Merge remote-tracking branch 'upstream/master'
thinkerou Feb 16, 2019
499d832
Merge remote-tracking branch 'upstream/master'
thinkerou Feb 16, 2019
c4798ae
Merge remote-tracking branch 'upstream/master'
thinkerou Feb 18, 2019
bd3e59d
Merge remote-tracking branch 'upstream/master'
thinkerou Feb 28, 2019
d10c611
Merge remote-tracking branch 'upstream/master'
thinkerou Feb 28, 2019
8e16470
Merge remote-tracking branch 'upstream/master'
thinkerou Mar 1, 2019
756ea90
change navbar color
thinkerou Mar 2, 2019
ae1fb75
Merge remote-tracking branch 'upstream/master'
thinkerou Mar 2, 2019
3e0ce80
tmp: update name for saving git log from gin repo
thinkerou Mar 3, 2019
28b0003
Merge remote-tracking branch 'upstream/master'
thinkerou Mar 3, 2019
a536691
fix conflict
thinkerou Mar 3, 2019
028ea9f
Merge remote-tracking branch 'upstream/master'
thinkerou Mar 4, 2019
d452778
Merge remote-tracking branch 'upstream/master'
thinkerou Mar 4, 2019
e5ac246
update
thinkerou Mar 4, 2019
4b87a4c
Merge remote-tracking branch 'upstream/master'
thinkerou Mar 4, 2019
7e5d5c5
Merge remote-tracking branch 'upstream/master'
thinkerou Mar 4, 2019
ceaf1d4
sync update doc from gin
thinkerou Mar 4, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,999 changes: 0 additions & 1,999 deletions GIN-README.md

This file was deleted.

Empty file modified content/en/blog/news/how-to-build-one-effective-middleware.md
100755 → 100644
Empty file.
Empty file modified content/en/blog/releases/release13.md
100755 → 100644
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -75,21 +75,3 @@ $ curl "http://localhost:8080/getd?field_x=hello&field_d=world"
{"d":"world","x":{"FieldX":"hello"}}
```

**NOTE**: NOT support the follow style struct:

```go
type StructX struct {
X struct {} `form:"name_x"` // HERE have form
}

type StructY struct {
Y StructX `form:"name_y"` // HERE have form
}

type StructZ struct {
Z *StructZ `form:"name_z"` // HERE have form
}
```

In a word, only support nested custom struct which have no `form` now.

6 changes: 2 additions & 4 deletions content/en/docs/examples/bind-single-binary-with-template.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ title: "Build a single binary with templates"
draft: false
---

You can build a server into a single binary containing templates by using [go-assets][].

[go-assets]: https://github.com/jessevdk/go-assets
You can build a server into a single binary containing templates by using [go-assets](https://github.com/jessevdk/go-assets).

```go
func main() {
Expand Down Expand Up @@ -43,5 +41,5 @@ 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.

33 changes: 33 additions & 0 deletions content/en/docs/examples/binding and validation
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# This viminfo file was generated by Vim 8.0.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing file extension?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@appleboy thanks! invalid file, I remove it!

# You may edit it if you're careful!

# Viminfo version
|1,4

# Value of 'encoding' when this file was written
*encoding=utf-8


# hlsearch on (H) or off (h):
~h
# Command Line History (newest to oldest):

# Search String History (newest to oldest):

# Expression History (newest to oldest):

# Input Line History (newest to oldest):

# Debug Line History (newest to oldest):

# Registers:

# File marks:
'0 1 0 ~/go/src/github.com/gin-gonic/website/content/en/docs/examples/grep
|4,48,1,0,1551702651,"~/go/src/github.com/gin-gonic/website/content/en/docs/examples/grep"

# Jumplist (newest first):
-' 1 0 ~/go/src/github.com/gin-gonic/website/content/en/docs/examples/grep
|4,39,1,0,1551702651,"~/go/src/github.com/gin-gonic/website/content/en/docs/examples/grep"

# History of marks within files (newest to oldest):
6 changes: 3 additions & 3 deletions content/en/docs/examples/binding-and-validation.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func main() {
// <?xml version="1.0" encoding="UTF-8"?>
// <root>
// <user>user</user>
// <password>123</user>
// <password>123</password>
// </root>)
router.POST("/loginXML", func(c *gin.Context) {
var xml Login
Expand Down Expand Up @@ -90,7 +90,7 @@ func main() {
}
```

#### Sample request
### Sample request

```sh
$ curl -v -X POST \
Expand All @@ -113,6 +113,6 @@ $ curl -v -X POST \
{"error":"Key: 'Login.Password' Error:Field validation for 'Password' failed on the 'required' tag"}
```

#### Skip validate
### Skip validate

When running the above example using the above the `curl` command, it returns error. Because the example use `binding:"required"` for `Password`. If use `binding:"-"` for `Password`, then it will not return error when running the above example again.
44 changes: 44 additions & 0 deletions content/en/docs/examples/controlling-log-output-coloring.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
title: "Controlling Log output coloring"
draft: false
---

By default, logs output on console should be colorized depending on the detected TTY.

Never colorize logs:

```go
func main() {
// Disable log's color
gin.DisableConsoleColor()

// Creates a gin router with default middleware:
// logger and recovery (crash-free) middleware
router := gin.Default()

router.GET("/ping", func(c *gin.Context) {
c.String(200, "pong")
})

router.Run(":8080")
}
```

Always colorize logs:

```go
func main() {
// Force log's color
gin.ForceConsoleColor()

// Creates a gin router with default middleware:
// logger and recovery (crash-free) middleware
router := gin.Default()

router.GET("/ping", func(c *gin.Context) {
c.String(200, "pong")
})

router.Run(":8080")
}
```
38 changes: 38 additions & 0 deletions content/en/docs/examples/custom-log-format.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
title: "Custom log file"
draft: false
---

For example:

```go
func main() {
router := gin.New()
// LoggerWithFormatter middleware will write the logs to gin.DefaultWriter
// By default gin.DefaultWriter = os.Stdout
router.Use(gin.LoggerWithFormatter(func(param gin.LogFormatterParams) string {
// your custom format
return fmt.Sprintf("%s - [%s] \"%s %s %s %d %s \"%s\" %s\"\n",
param.ClientIP,
param.TimeStamp.Format(time.RFC1123),
param.Method,
param.Path,
param.Request.Proto,
param.StatusCode,
param.Latency,
param.Request.UserAgent(),
param.ErrorMessage,
)
}))
router.Use(gin.Recovery())
router.GET("/ping", func(c *gin.Context) {
c.String(200, "pong")
})
router.Run(":8080")
}
```

**Sample Output**
```
::1 - [Fri, 07 Dec 2018 17:04:38 JST] "GET /ping HTTP/1.1 200 122.767µs "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.80 Safari/537.36" "
```
2 changes: 1 addition & 1 deletion content/en/docs/examples/custom-validators.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ title: "Custom validators"
draft: false
---

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/struct-lvl-validations).

```go
package main
Expand Down
13 changes: 11 additions & 2 deletions content/en/docs/examples/graceful-restart-or-stop.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,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
Expand All @@ -34,6 +34,7 @@ import (
"net/http"
"os"
"os/signal"
"syscall"
"time"

"github.com/gin-gonic/gin"
Expand Down Expand Up @@ -61,7 +62,10 @@ func main() {
// Wait for interrupt signal to gracefully shutdown the server with
// a timeout of 5 seconds.
quit := make(chan os.Signal)
signal.Notify(quit, os.Interrupt)
// kill (no param) default send syscanll.SIGTERM
// kill -2 is syscall.SIGINT
// kill -9 is syscall. SIGKILL but can"t be catch, so don't need add it
signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
<-quit
log.Println("Shutdown Server ...")

Expand All @@ -70,6 +74,11 @@ func main() {
if err := srv.Shutdown(ctx); err != nil {
log.Fatal("Server Shutdown:", err)
}
// catching ctx.Done(). timeout of 5 seconds.
select {
case <-ctx.Done():
log.Println("timeout of 5 seconds.")
}
log.Println("Server exiting")
}
```
Expand Down
8 changes: 4 additions & 4 deletions content/en/docs/examples/html-rendering.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ templates/users/index.tmpl
{{ end }}
```

#### Custom Template renderer
### Custom Template renderer

You can also use your own html template render

Expand All @@ -88,7 +88,7 @@ func main() {
}
```

#### Custom Delimiters
### Custom Delimiters

You may use custom delims

Expand All @@ -98,9 +98,9 @@ You may use custom delims
r.LoadHTMLGlob("/path/to/templates")
```

#### Custom Template Funcs
### 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

Expand Down
3 changes: 0 additions & 3 deletions content/en/docs/examples/http-method.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ draft: false

```go
func main() {
// Disable Console Color
// gin.DisableConsoleColor()

// Creates a gin router with default middleware:
// logger and recovery (crash-free) middleware
router := gin.Default()
Expand Down
2 changes: 1 addition & 1 deletion content/en/docs/examples/upload-file/multiple-file.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ title: "Multiple files"
draft: false
---

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() {
Expand Down
6 changes: 5 additions & 1 deletion content/en/docs/examples/upload-file/single-file.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ title: "Single file"
draft: false
---

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)

> The filename is always optional and must not be used blindly by the application: path information should be stripped, and conversion to the server file system rules should be done.

```go
func main() {
Expand Down
2 changes: 1 addition & 1 deletion content/en/docs/jsoniter/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ draft: false
weight: 5
---

#### Build with [jsoniter](https://github.com/json-iterator/go)
## Build with [jsoniter](https://github.com/json-iterator/go)

Gin uses `encoding/json` as default json package but you can change to [jsoniter](https://github.com/json-iterator/go) by build from other tags.

Expand Down
10 changes: 3 additions & 7 deletions content/en/docs/quickstart/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,13 @@ draft: false
weight: 2
---

- [Requirements](#requirements)
- [Installation](#installation)
- [Getting started](#getting-started)

In this quickstart, we’ll glean insights from code segments and learn how to:

## Requirements

- Go 1.6 or above

> Go 1.7 or Go 1.8 will be required soon.
> Go 1.7 or Go 1.8 will be no longer supported soon.

## Installation

Expand All @@ -38,7 +34,7 @@ import "github.com/gin-gonic/gin"
import "net/http"
```

#### Use a vendor tool like [Govendor](https://github.com/kardianos/govendor)
### Use a vendor tool like [Govendor](https://github.com/kardianos/govendor)

1. `go get` govendor

Expand All @@ -61,7 +57,7 @@ $ govendor fetch github.com/gin-gonic/[email protected]
4. Copy a starting template inside your project

```sh
$ curl https://test2-for-worker.haf208.cc/gin-gonic/gin/master/examples/basic/main.go > main.go
$ curl https://test2-for-worker.haf208.cc/gin-gonic/examples/master/basic/main.go > main.go
```

5. Run your project
Expand Down
Empty file modified content/en/featured-background.jpg
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.