Gin is a HTTP web framework written in Go (Golang). It features a Martini-like API with much better performance -- up to 40 times faster. If you need smashing performance, get yourself some Gin.
Go to file
田欧 1d462bbe37
chore: update ginS (#1822)
2019-03-21 15:12:06 +08:00
.github chore: update issue_implate (#1524) 2018-09-01 00:40:33 +08:00
binding update for supporting file binding (#1264) 2019-03-18 10:16:34 +08:00
examples Doc: fix gin example notice syntax (#1814) 2019-03-15 15:39:34 +08:00
ginS chore: update ginS (#1822) 2019-03-21 15:12:06 +08:00
internal/json chore: use internal/json (#1791) 2019-03-05 06:46:18 +08:00
render issue_1721: fix render writeHeaders to make it the same as http.Header.Set (#1722) 2019-02-22 14:20:24 +08:00
testdata chore: fix invalid link (#1820) 2019-03-20 12:07:34 +08:00
vendor Split examples to alone repo (#1776) 2019-03-01 23:42:41 +08:00
.gitignore ci: break when test fail (#1671) 2018-12-05 13:49:03 +08:00
.travis.yml Remove sudo setting from travis.yml (#1816) 2019-03-16 16:09:10 +08:00
AUTHORS.md docs: add changelog for v1.3.0, update authors and version const (#1478) 2018-08-14 10:58:52 +02:00
BENCHMARKS.md docs(benchmark): update benchmark data (#1035) 2017-07-19 09:40:05 +02:00
CHANGELOG.md docs: add changelog for v1.3.0, update authors and version const (#1478) 2018-08-14 10:58:52 +02:00
CODE_OF_CONDUCT.md docs(conduct): add code of conduct 2017-07-05 18:25:37 +02:00
CONTRIBUTING.md update document format. (#964) 2017-07-02 09:41:06 -05:00
LICENSE Add MIT license 2014-06-30 16:54:02 -04:00
Makefile Split examples to alone repo (#1776) 2019-03-01 23:42:41 +08:00
README.md chore: fix invalid link (#1820) 2019-03-20 12:07:34 +08:00
auth.go remove hardcode instead of http status value (#1411) 2018-06-26 17:21:32 +08:00
auth_test.go replace deprecated HeaderMap with Header() (#1585) 2018-10-12 07:31:31 +08:00
benchmarks_test.go chore: use http.Status* instead of hard code (#1482) 2018-08-14 09:51:56 +08:00
codecov.yml Add codecov.yml Gitter webhook 2016-10-28 21:41:18 +02:00
context.go Added stream flag indicates if client disconnected in middle of streaming (#1252) 2019-03-02 23:07:37 +08:00
context_17.go Revert "context: inherits context cancelation and deadline from http.Request context for Go>=1.7 (#1690)" (#1736) 2019-01-09 09:32:44 +08:00
context_17_test.go Revert "context: inherits context cancelation and deadline from http.Request context for Go>=1.7 (#1690)" (#1736) 2019-01-09 09:32:44 +08:00
context_appengine.go Add license for some files (#940) 2017-06-12 01:04:52 -05:00
context_test.go Extend context.File to allow for the content-dispositon attachments via a new method context.Attachment (#1260) 2019-03-01 10:17:47 +08:00
debug.go Make sure the debug log contains line breaks (#1650) 2018-11-22 09:07:00 +08:00
debug_test.go Make silent debug info on tests (#1765) 2019-02-18 10:10:45 +08:00
deprecated.go fix typo (#1103) 2017-09-08 08:56:56 +08:00
deprecated_test.go Make silent debug info on tests (#1765) 2019-02-18 10:10:45 +08:00
doc.go chore: fix invalid link (#1820) 2019-03-20 12:07:34 +08:00
errors.go spell check (#1796) 2019-03-05 09:41:37 +08:00
errors_test.go fix errcheck warnings (#1739) 2019-01-18 09:32:53 +08:00
fs.go update comment (#1057) 2017-08-16 11:55:50 +08:00
gin.go spell check (#1796) 2019-03-05 09:41:37 +08:00
gin_integration_test.go fix travis freeze on concurrent test (#1761) 2019-02-04 09:27:00 +08:00
gin_test.go Make silent debug info on tests (#1765) 2019-02-18 10:10:45 +08:00
githubapi_test.go Fix context.Copy() race condition (#1020) 2019-02-26 15:10:16 +08:00
go.mod chore: update go mod package (#1792) 2019-03-04 07:28:03 +08:00
go.sum chore: update go mod package (#1792) 2019-03-04 07:28:03 +08:00
logger.go IsTerm flag should not be affected by DisableConsoleColor method. (#1802) 2019-03-18 11:12:30 +08:00
logger_test.go IsTerm flag should not be affected by DisableConsoleColor method. (#1802) 2019-03-18 11:12:30 +08:00
middleware_test.go fix errcheck warnings (#1739) 2019-01-18 09:32:53 +08:00
mode.go Use camel case instead of ALL_CAPS (#1419) 2019-02-22 12:53:47 +08:00
mode_test.go Use camel case instead of ALL_CAPS (#1419) 2019-02-22 12:53:47 +08:00
path.go small enhance for cleanPath (#1469) 2018-08-10 20:50:23 +08:00
path_test.go add an edge case from httprouter (#1407) 2018-06-23 11:06:27 +08:00
recovery.go spell check (#1796) 2019-03-05 09:41:37 +08:00
recovery_test.go Make silent debug info on tests (#1765) 2019-02-18 10:10:45 +08:00
response_writer.go flush operation will overwrite the origin status code (#1460) 2018-08-07 12:41:28 +08:00
response_writer_1.7.go Add Pusher() function for support http2 server push (#1273) 2018-06-21 09:53:52 +08:00
response_writer_1.8.go Add Pusher() function for support http2 server push (#1273) 2018-06-21 09:53:52 +08:00
response_writer_test.go fix errcheck warnings (#1739) 2019-01-18 09:32:53 +08:00
routergroup.go fix #1804 which is caused by calling middleware twice. (#1805) 2019-03-11 10:52:47 +08:00
routergroup_test.go chore: use http.Status* instead of hard code (#1482) 2018-08-14 09:51:56 +08:00
routes_test.go fix #1804 which is caused by calling middleware twice. (#1805) 2019-03-11 10:52:47 +08:00
test_helpers.go Attempt to fix #1462 (#1463) 2018-08-12 10:12:33 +08:00
tree.go improve panic information when a catch-all wildcard conflict occurs (#1529) 2018-09-21 10:21:59 +08:00
tree_test.go support bind uri param (#1612) 2018-11-22 09:29:48 +08:00
utils.go chore: add some annotations (#1544) 2018-09-15 10:23:32 +08:00
utils_test.go chore: use http.Status* instead of hard code (#1482) 2018-08-14 09:51:56 +08:00
version.go chore: add a version file includes gin version (#1549) 2018-09-17 15:08:11 +08:00

README.md

Gin Web Framework

Build Status codecov Go Report Card GoDoc Join the chat at https://gitter.im/gin-gonic/gin Sourcegraph Open Source Helpers Release

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. If you need performance and good productivity, you will love Gin.

The key features of Gin are:

  • Zero allocation router
  • Fast
  • Middleware support
  • Crash-free
  • JSON validation
  • Routes grouping
  • Error management
  • Rendering built-in
  • Extendable

For more feature details, please see the Gin website introduction.

Getting started

Getting Gin

The first need Go installed (version 1.6+ is required), then you can use the below Go command to install Gin.

$ go get -u github.com/gin-gonic/gin

For more installation guides such as vendor tool, please check out Gin quickstart.

Running Gin

First you need to import Gin package for using Gin, one simplest example likes the follow example.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
}

And use the Go command to run the demo:

# run example.go and visit 0.0.0.0:8080/ping on browser
$ go run example.go

Benchmarks

Please see all benchmarks details from Gin website.

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
BenchmarkVulcan_GithubAll 5000 394253 19894 609
  • (1): Total Repetitions achieved in constant time, higher means more confident result
  • (2): Single Repetition Duration (ns/op), lower is better
  • (3): Heap Memory (B/op), lower is better
  • (4): Average Allocations per Repetition (allocs/op), lower is better

Middlewares

You can find many useful Gin middlewares at gin-contrib.

Documentation

See API documentation and descriptions for package.

All documentation is available on the Gin website.

Examples

A number of ready-to-run examples demonstrating various use cases of Gin on the Gin examples repository.

Users

Gin website lists some awesome projects made with Gin web framework.

Contributing

Gin is the work of hundreds of contributors. We appreciate your help!

Please see CONTRIBUTING for details on submitting patches and the contribution workflow.