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 the documentation to explain configuration items. #277

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
39 changes: 39 additions & 0 deletions content/en/docs/deployment/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,42 @@ Follow the Render [guide to deploying Gin projects](https://render.com/docs/depl
GAE has two ways to deploy Go applications. The standard environment is easier to use but less customizable and prevents [syscalls](https://github.com/gin-gonic/gin/issues/1639) for security reasons. The flexible environment can run any framework or library.

Learn more and pick your preferred environment at [Go on Google App Engine](https://cloud.google.com/appengine/docs/go/).


## Self Hosted
Gin projects can also be deployed in a self-hosted manner. Deployment architecture and security considerations vary depending on the target environment. The following section only presents a high level overview of configuration options to consider when planning the deployment.

## Configuration Options
Gin project deployments can be tuned by using environment variables or directly in code.

The following environment variables are available for configuring Gin:

| Environment Variable | Description |
|----------------------|-------------|
| PORT | The TCP port to listen on when starting the Gin server with `router.Run()` (i.e. without any arguments). |
| GIN_MODE | Set to one of `debug`, `release`, or `test`. Handles management of Gin modes, such as when to emit debug outputs. Can also be set in code using `gin.SetMode(gin.ReleaseMode)` or `gin.SetMode(gin.TestMode)`|

The following code can be used to configure Gin.

```go
// Don't specify the bind address or port for Gin. Defaults to binding on all interfaces on port 8080.
// Can use the `PORT` environment variable to change the listen port when using `Run()` without any arguments.
router := gin.Default()
router.Run()

// Specify the bind address and port for Gin.
router := gin.Default()
router.Run("192.168.1.100:8080")

// Specify only the listen port. Will bind on all interfaces.
router := gin.Default()
router.Run(":8080")

// Set which IP addresses or CIDRs, are considered to be trusted for setting headers to document real client IP addresses.
// See the documentation for additional details.
router := gin.Default()
router.SetTrustedProxies([]string{"192.168.1.2"})
```

## Don't Trust All Proxies
By default, Gin will trust all proxies. This should be considered and tuned according to your deployment architecture. See the [Gin Documentation](https://github.com/gin-gonic/gin/blob/master/docs/doc.md#dont-trust-all-proxies) for additional details.
2 changes: 2 additions & 0 deletions content/en/docs/quickstart/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,5 @@ And, You can run the code via `go run example.go`:
# run example.go and visit 0.0.0.0:8080/ping on browser
$ go run example.go
```

Additional information is available from the [Gin source code repository](https://github.com/gin-gonic/gin/blob/master/docs/doc.md).