Skip to content

Commit

Permalink
update newest doc from gin readme (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkerou authored Mar 4, 2019
1 parent 189d8e1 commit 3e5cbe7
Show file tree
Hide file tree
Showing 18 changed files with 146 additions and 2,044 deletions.
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.
# 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/gin@v1.3
4. Copy a starting template inside your project

```sh
$ curl https://raw.githubusercontent.com/gin-gonic/gin/master/examples/basic/main.go > main.go
$ curl https://raw.githubusercontent.com/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.

0 comments on commit 3e5cbe7

Please sign in to comment.