# 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
没有合适的资源?快使用搜索试试~ 我知道了~
Go-goim是一个golang写的IM服务器
共1432个文件
go:1103个
proto:65个
md:52个
需积分: 37 19 下载量 10 浏览量
2019-08-13
23:46:23
上传
评论 2
收藏 3.53MB ZIP 举报
温馨提示
goim是一个即时通讯服务器,代码全部使用golang完成,功能包含好友之间一对一聊天,群组聊天,支持单用户多设备同时在线,就像微信一样
资源推荐
资源详情
资源评论
收起资源包目录
Go-goim是一个golang写的IM服务器 (1432个子文件)
AUTHORS 3KB
AUTHORS 173B
AUTHORS 173B
cpu_gccgo.c 1KB
gccgo_c.c 1KB
go12.c 497B
codereview.cfg 21B
docker.cnf 70B
CONTRIBUTORS 170B
CONTRIBUTORS 170B
epoch.min.css 58KB
prismjs.min.css 2KB
Dockerfile 2KB
.gitattributes 345B
.gitignore 307B
.gitignore 293B
.gitignore 259B
.gitignore 175B
.gitignore 90B
.gitignore 84B
.gitignore 84B
.gitignore 57B
.gitignore 42B
.gitignore 22B
.gitignore 16B
.gitignore 14B
.gitignore 8B
fast-path.generated.go 807KB
mammoth2_codecgen_generated_test.go 776KB
mammoth_generated_test.go 466KB
test.pb.go 182KB
validator_test.go 139KB
zerrors_linux_ppc64le.go 121KB
zerrors_linux_ppc64.go 121KB
zerrors_linux_s390x.go 121KB
datastore_v3.pb.go 119KB
zerrors_linux_mips64le.go 119KB
zerrors_linux_mipsle.go 119KB
zerrors_linux_mips64.go 119KB
zerrors_linux_mips.go 119KB
zerrors_linux_arm.go 118KB
zerrors_linux_amd64.go 118KB
zerrors_linux_386.go 118KB
zerrors_linux_arm64.go 118KB
zerrors_linux_riscv64.go 117KB
descriptor.pb.go 115KB
generator.go 101KB
taskqueue_service.pb.go 93KB
search.pb.go 91KB
socket_service.pb.go 90KB
zsyscall_windows.go 89KB
zerrors_linux_sparc64.go 86KB
codec_test.go 84KB
scannerc.go 75KB
conformance.pb.go 75KB
all_test.go 74KB
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
helper.go 67KB
zerrors_dragonfly_amd64.go 67KB
decode.go 65KB
gen.go 64KB
types.go 59KB
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_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
zsyscall_linux_sparc64.go 52KB
zerrors_aix_ppc.go 52KB
zsyscall_linux_386.go 52KB
zsyscall_linux_s390x.go 52KB
ztypes_linux_s390x.go 50KB
driver_test.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
共 1432 条
- 1
- 2
- 3
- 4
- 5
- 6
- 15
资源评论
weixin_39840387
- 粉丝: 780
- 资源: 3万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功