# Gin Web Framework
<img align="right" width="159px" src="https://raw.githubusercontent.com/gin-gonic/logo/master/color.png">
[![Build Status](https://travis-ci.org/gin-gonic/gin.svg)](https://travis-ci.org/gin-gonic/gin)
[![codecov](https://codecov.io/gh/gin-gonic/gin/branch/master/graph/badge.svg)](https://codecov.io/gh/gin-gonic/gin)
[![Go Report Card](https://goreportcard.com/badge/github.com/gin-gonic/gin)](https://goreportcard.com/report/github.com/gin-gonic/gin)
[![GoDoc](https://godoc.org/github.com/gin-gonic/gin?status.svg)](https://godoc.org/github.com/gin-gonic/gin)
[![Join the chat at https://gitter.im/gin-gonic/gin](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/gin-gonic/gin?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[![Sourcegraph](https://sourcegraph.com/github.com/gin-gonic/gin/-/badge.svg)](https://sourcegraph.com/github.com/gin-gonic/gin?badge)
[![Open Source Helpers](https://www.codetriage.com/gin-gonic/gin/badges/users.svg)](https://www.codetriage.com/gin-gonic/gin)
Gin is a web framework written in Go (Golang). It features a martini-like API with much better performance, up to 40 times faster thanks to [httprouter](https://github.com/julienschmidt/httprouter). If you need performance and good productivity, you will love Gin.
![Gin console logger](https://gin-gonic.github.io/gin/other/console.png)
## Contents
- [Installation](#installation)
- [Prerequisite](#prerequisite)
- [Quick start](#quick-start)
- [Benchmarks](#benchmarks)
- [Gin v1.stable](#gin-v1-stable)
- [Build with jsoniter](#build-with-jsoniter)
- [API Examples](#api-examples)
- [Using GET,POST,PUT,PATCH,DELETE and OPTIONS](#using-get-post-put-patch-delete-and-options)
- [Parameters in path](#parameters-in-path)
- [Querystring parameters](#querystring-parameters)
- [Multipart/Urlencoded Form](#multiparturlencoded-form)
- [Another example: query + post form](#another-example-query--post-form)
- [Map as querystring or postform parameters](#map-as-querystring-or-postform-parameters)
- [Upload files](#upload-files)
- [Grouping routes](#grouping-routes)
- [Blank Gin without middleware by default](#blank-gin-without-middleware-by-default)
- [Using middleware](#using-middleware)
- [How to write log file](#how-to-write-log-file)
- [Model binding and validation](#model-binding-and-validation)
- [Custom Validators](#custom-validators)
- [Only Bind Query String](#only-bind-query-string)
- [Bind Query String or Post Data](#bind-query-string-or-post-data)
- [Bind HTML checkboxes](#bind-html-checkboxes)
- [Multipart/Urlencoded binding](#multiparturlencoded-binding)
- [XML, JSON and YAML rendering](#xml-json-and-yaml-rendering)
- [JSONP rendering](#jsonp)
- [Serving static files](#serving-static-files)
- [Serving data from reader](#serving-data-from-reader)
- [HTML rendering](#html-rendering)
- [Multitemplate](#multitemplate)
- [Redirects](#redirects)
- [Custom Middleware](#custom-middleware)
- [Using BasicAuth() middleware](#using-basicauth-middleware)
- [Goroutines inside a middleware](#goroutines-inside-a-middleware)
- [Custom HTTP configuration](#custom-http-configuration)
- [Support Let's Encrypt](#support-lets-encrypt)
- [Run multiple service using Gin](#run-multiple-service-using-gin)
- [Graceful restart or stop](#graceful-restart-or-stop)
- [Build a single binary with templates](#build-a-single-binary-with-templates)
- [Bind form-data request with custom struct](#bind-form-data-request-with-custom-struct)
- [Try to bind body into different structs](#try-to-bind-body-into-different-structs)
- [http2 server push](#http2-server-push)
- [Testing](#testing)
- [Users](#users--)
## Installation
To install Gin package, you need to install Go and set your Go workspace first.
1. Download and install it:
```sh
$ go get -u github.com/gin-gonic/gin
```
2. Import it in your code:
```go
import "github.com/gin-gonic/gin"
```
3. (Optional) Import `net/http`. This is required for example if using constants such as `http.StatusOK`.
```go
import "net/http"
```
### Use a vendor tool like [Govendor](https://github.com/kardianos/govendor)
1. `go get` govendor
```sh
$ go get github.com/kardianos/govendor
```
2. Create your project folder and `cd` inside
```sh
$ mkdir -p $GOPATH/src/github.com/myusername/project && cd "$_"
```
3. Vendor init your project and add gin
```sh
$ govendor init
$ govendor fetch github.com/gin-gonic/gin@v1.2
```
4. Copy a starting template inside your project
```sh
$ curl https://raw.githubusercontent.com/gin-gonic/gin/master/examples/basic/main.go > main.go
```
5. Run your project
```sh
$ go run main.go
```
## Prerequisite
Now Gin requires Go 1.6 or later and Go 1.7 will be required soon.
## Quick start
```sh
# assume the following codes in example.go file
$ cat example.go
```
```go
package main
import "github.com/gin-gonic/gin"
func main() {
r := gin.Default()
r.GET("/ping", func(c *gin.Context) {
c.JSON(200, gin.H{
"message": "pong",
})
})
r.Run() // listen and serve on 0.0.0.0:8080
}
```
```
# run example.go and visit 0.0.0.0:8080/ping on browser
$ go run example.go
```
## Benchmarks
Gin uses a custom version of [HttpRouter](https://github.com/julienschmidt/httprouter)
[See all benchmarks](/BENCHMARKS.md)
Benchmark name | (1) | (2) | (3) | (4)
--------------------------------------------|-----------:|------------:|-----------:|---------:
**BenchmarkGin_GithubAll** | **30000** | **48375** | **0** | **0**
BenchmarkAce_GithubAll | 10000 | 134059 | 13792 | 167
BenchmarkBear_GithubAll | 5000 | 534445 | 86448 | 943
BenchmarkBeego_GithubAll | 3000 | 592444 | 74705 | 812
BenchmarkBone_GithubAll | 200 | 6957308 | 698784 | 8453
BenchmarkDenco_GithubAll | 10000 | 158819 | 20224 | 167
BenchmarkEcho_GithubAll | 10000 | 154700 | 6496 | 203
BenchmarkGocraftWeb_GithubAll | 3000 | 570806 | 131656 | 1686
BenchmarkGoji_GithubAll | 2000 | 818034 | 56112 | 334
BenchmarkGojiv2_GithubAll | 2000 | 1213973 | 274768 | 3712
BenchmarkGoJsonRest_GithubAll | 2000 | 785796 | 134371 | 2737
BenchmarkGoRestful_GithubAll | 300 | 5238188 | 689672 | 4519
BenchmarkGorillaMux_GithubAll | 100 | 10257726 | 211840 | 2272
BenchmarkHttpRouter_GithubAll | 20000 | 105414 | 13792 | 167
BenchmarkHttpTreeMux_GithubAll | 10000 | 319934 | 65856 | 671
BenchmarkKocha_GithubAll | 10000 | 209442 | 23304 | 843
BenchmarkLARS_GithubAll | 20000 | 62565 | 0 | 0
BenchmarkMacaron_GithubAll | 2000 | 1161270 | 204194 | 2000
BenchmarkMartini_GithubAll | 200 | 9991713 | 226549 | 2325
BenchmarkPat_GithubAll | 200 | 5590793 | 1499568 | 27435
BenchmarkPossum_GithubAll | 10000 | 319768 | 84448 | 609
BenchmarkR2router_GithubAll | 10000 | 305134 | 77328 | 979
BenchmarkRivet_GithubAll | 10000 | 132134 | 16272 | 167
BenchmarkTango_GithubAll | 3000 | 552754 | 63826 | 1618
BenchmarkTigerTonic_GithubAll | 1000 | 1439483 | 239104 | 5374
BenchmarkTraffic_GithubAll | 100 | 11383067 | 2659329 | 21848
Bench
没有合适的资源?快使用搜索试试~ 我知道了~
使用 gin 和 MongoDB 完成的 IoT 管理平台后端.zip
共609个文件
go:471个
s:33个
md:21个
需积分: 0 1 下载量 160 浏览量
2024-03-03
17:18:45
上传
评论
收藏 1.94MB ZIP 举报
温馨提示
使用 gin 和 MongoDB 完成的 IoT 管理平台后端.zip
资源推荐
资源详情
资源评论
收起资源包目录
使用 gin 和 MongoDB 完成的 IoT 管理平台后端.zip (609个子文件)
AUTHORS 173B
AUTHORS 173B
sasl_windows.c 4KB
sspi_windows.c 3KB
sasl.c 2KB
gccgo_c.c 1KB
CONTRIBUTORS 170B
CONTRIBUTORS 170B
Dockerfile 310B
.gitignore 307B
.gitignore 57B
.gitignore 42B
.gitignore 22B
.gitignore 16B
.gitignore 16B
.gitignore 14B
fast-path.generated.go 799KB
session.go 145KB
zerrors_linux_ppc64le.go 123KB
zerrors_linux_ppc64.go 123KB
zerrors_linux_s390x.go 122KB
zerrors_linux_mips64le.go 120KB
zerrors_linux_mipsle.go 120KB
zerrors_linux_mips64.go 120KB
zerrors_linux_mips.go 120KB
zerrors_linux_arm.go 120KB
zerrors_linux_amd64.go 120KB
zerrors_linux_386.go 120KB
zerrors_linux_arm64.go 119KB
zerrors_linux_riscv64.go 119KB
zerrors_linux_sparc64.go 86KB
scannerc.go 75KB
zerrors_darwin_amd64.go 73KB
zerrors_darwin_arm64.go 73KB
zerrors_darwin_386.go 73KB
zerrors_darwin_arm.go 73KB
table_marshal.go 73KB
zerrors_netbsd_386.go 72KB
zerrors_openbsd_amd64.go 72KB
zerrors_netbsd_amd64.go 72KB
zerrors_netbsd_arm.go 72KB
zerrors_freebsd_arm.go 70KB
zerrors_freebsd_amd64.go 70KB
zerrors_freebsd_386.go 70KB
zerrors_openbsd_arm.go 68KB
zerrors_openbsd_386.go 68KB
zerrors_dragonfly_amd64.go 67KB
helper.go 64KB
gen.go 64KB
decode.go 62KB
zerrors_solaris_amd64.go 58KB
zsyscall_linux_ppc64le.go 58KB
zsyscall_linux_ppc64.go 58KB
zsyscall_linux_mipsle.go 57KB
zsyscall_linux_mips.go 57KB
zsyscall_linux_amd64.go 57KB
zsyscall_linux_sparc64.go 56KB
zsyscall_linux_mips64le.go 56KB
zsyscall_linux_mips64.go 56KB
baked_in.go 55KB
zsyscall_linux_arm.go 55KB
zsyscall_solaris_amd64.go 54KB
zsyscall_linux_riscv64.go 53KB
zsyscall_linux_arm64.go 53KB
zerrors_aix_ppc64.go 52KB
zerrors_aix_ppc.go 52KB
zsyscall_linux_386.go 52KB
zsyscall_linux_s390x.go 52KB
ztypes_linux_s390x.go 50KB
ztypes_linux_amd64.go 50KB
ztypes_linux_riscv64.go 50KB
ztypes_linux_ppc64le.go 49KB
ztypes_linux_ppc64.go 49KB
ztypes_linux_mips64le.go 49KB
ztypes_linux_mips64.go 49KB
ztypes_linux_arm64.go 49KB
ztypes_linux_386.go 49KB
ztypes_linux_mipsle.go 49KB
ztypes_linux_mips.go 49KB
ztypes_linux_arm.go 49KB
table_unmarshal.go 49KB
zsyscall_freebsd_arm.go 48KB
zsyscall_freebsd_386.go 48KB
zsyscall_freebsd_amd64.go 48KB
syscall_linux.go 48KB
emitterc.go 44KB
zsyscall_netbsd_arm.go 43KB
zsyscall_netbsd_386.go 43KB
zsyscall_netbsd_amd64.go 43KB
zsyscall_darwin_arm.go 42KB
zsyscall_darwin_386.go 42KB
zsyscall_darwin_amd64.go 41KB
zsyscall_darwin_arm64.go 41KB
zsyscall_aix_ppc64_gc.go 41KB
decode.go 40KB
zsyscall_openbsd_arm.go 40KB
zsyscall_openbsd_386.go 40KB
zsyscall_openbsd_amd64.go 39KB
zsyscall_dragonfly_amd64.go 38KB
encode.go 36KB
共 609 条
- 1
- 2
- 3
- 4
- 5
- 6
- 7
资源评论
日刷百题
- 粉丝: 5186
- 资源: 951
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功