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
Bo-Yi Wu 160c1730ef
chore: update GitHub Actions configuration (#3792)
- Change the cron schedule from `'0 17 * * 5'` to `"0 17 * * 5"` in the file `.github/workflows/codeql.yml`
- Change the value of `language` from `['go']` to `["go"]` in the file `.github/workflows/codeql.yml`
- Change the value of `go-version` from `'^1.18'` to `"^1.18"` in the file `.github/workflows/gin.yml`
- Add `1.21` to the list of `go` versions and change the value of `test-tags` in the file `.github/workflows/gin.yml`
- Change the value of `if` condition from `matrix.go-version == '1.20.x'` to `matrix.go-version == '1.21.x'` in the file `.github/workflows/gin.yml`
- Change the value of `on` from `'*'` to `"*"` in the file `.github/workflows/goreleaser.yml`
- Change the name of the job from `name: Checkout` to `name: Checkout` in the file `.github/workflows/goreleaser.yml`
- Change the name of the job from `name: Set up Go` to `name: Set up Go` in the file `.github/workflows/goreleaser.yml`
- Change the value of `go-version` from `1.20` to `"^1"` in

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2024-01-19 00:35:08 +08:00
.github chore: update GitHub Actions configuration (#3792) 2024-01-19 00:35:08 +08:00
binding fix: Add pointer support for url query params (#3659) (#3666) 2023-11-16 23:46:43 +08:00
docs chore: support min go version 1.18 (#3511) 2023-03-01 10:03:48 +08:00
examples Doc: fix gin example notice syntax (#1814) 2019-03-15 15:39:34 +08:00
ginS chore: upgrade golangci-lint and fix golangci-lint error (#3278) 2022-08-15 21:38:20 +08:00
internal Convert strings and slices using the officially recommended way (#3344) 2023-03-02 08:12:20 +08:00
render test(render): increased unit tests coverage (#3691) 2023-08-12 22:21:56 +08:00
testdata chore: support min go version 1.18 (#3511) 2023-03-01 10:03:48 +08:00
.gitignore ci: break when test fail (#1671) 2018-12-05 13:49:03 +08:00
.golangci.yml chore: improve linting, testing, and GitHub Actions setup (#3583) 2023-04-26 14:13:56 +08:00
.goreleaser.yaml chore(CI/CD): add go version release flow (#3159) 2022-05-28 15:23:00 +08:00
AUTHORS.md add v1.8.0 changelog (#3160) 2022-05-30 15:16:10 +08:00
BENCHMARKS.md chore: Deleted spaces (#2622) 2021-01-27 09:58:21 +08:00
CHANGELOG.md Ready release gin 1.9.1 (by: thinkerou) (#3630) 2023-06-01 10:26:20 +08:00
CODE_OF_CONDUCT.md docs(conduct): add code of conduct 2017-07-05 18:25:37 +02:00
CONTRIBUTING.md ci: add github action workflows (#2596) 2021-06-23 13:10:49 +08:00
LICENSE Add MIT license 2014-06-30 16:54:02 -04:00
Makefile feat: add sonic json support (#3184) 2022-08-02 10:20:59 +08:00
README.md chore: improve linting, testing, and GitHub Actions setup (#3583) 2023-04-26 14:13:56 +08:00
auth.go chore: update go.mod and remove space from copyright (#3158) 2022-05-28 10:42:28 +08:00
auth_test.go chore: update go.mod and remove space from copyright (#3158) 2022-05-28 10:42:28 +08:00
benchmarks_test.go chore: update go.mod and remove space from copyright (#3158) 2022-05-28 10:42:28 +08:00
context.go fix Request.Context() checks (#3512) 2023-05-29 09:59:35 +08:00
context_1.18_test.go chore: support min go version 1.18 (#3511) 2023-03-01 10:03:48 +08:00
context_1.19_test.go chore: support min go version 1.18 (#3511) 2023-03-01 10:03:48 +08:00
context_appengine.go chore: support min go version 1.18 (#3511) 2023-03-01 10:03:48 +08:00
context_test.go fix Request.Context() checks (#3512) 2023-05-29 09:59:35 +08:00
debug.go chore: support min go version 1.18 (#3511) 2023-03-01 10:03:48 +08:00
debug_test.go chore: support min go version 1.18 (#3511) 2023-03-01 10:03:48 +08:00
deprecated.go chore: support min go version 1.18 (#3511) 2023-03-01 10:03:48 +08:00
deprecated_test.go chore: update go.mod and remove space from copyright (#3158) 2022-05-28 10:42:28 +08:00
doc.go chore: fix invalid link (#1820) 2019-03-20 12:07:34 +08:00
errors.go fix: modify interface check way (#3327) 2022-10-20 00:49:19 +08:00
errors_test.go chore: upgrade golangci-lint and fix golangci-lint error (#3278) 2022-08-15 21:38:20 +08:00
fs.go chore: improve linting, testing, and GitHub Actions setup (#3583) 2023-04-26 14:13:56 +08:00
gin.go docs: remove redundant comments (#3765) 2023-11-16 23:46:11 +08:00
gin_integration_test.go remove deprecated of package io/ioutil (#3395) 2022-11-17 22:35:55 +08:00
gin_test.go remove deprecated of package io/ioutil (#3395) 2022-11-17 22:35:55 +08:00
githubapi_test.go Replace bytes.Buffer with strings.Builder where appropriate (#3347) 2023-01-20 09:51:42 +08:00
go.mod chore(deps): bump github.com/pelletier/go-toml/v2 from 2.0.8 to 2.1.1 (#3797) 2023-12-13 10:28:51 +08:00
go.sum chore(deps): bump github.com/pelletier/go-toml/v2 from 2.0.8 to 2.1.1 (#3797) 2023-12-13 10:28:51 +08:00
logger.go chore(http): use white color for HTTP 1XX (#3741) 2023-09-27 15:17:11 +08:00
logger_test.go chore(http): use white color for HTTP 1XX (#3741) 2023-09-27 15:17:11 +08:00
middleware_test.go chore: upgrade golangci-lint and fix golangci-lint error (#3278) 2022-08-15 21:38:20 +08:00
mode.go chore: upgrade golangci-lint and fix golangci-lint error (#3278) 2022-08-15 21:38:20 +08:00
mode_test.go chore: update go.mod and remove space from copyright (#3158) 2022-05-28 10:42:28 +08:00
path.go chore: upgrade golangci-lint and fix golangci-lint error (#3278) 2022-08-15 21:38:20 +08:00
path_test.go Reuse bytes when cleaning the URL paths (#2179) 2020-01-07 17:37:18 +08:00
recovery.go chore: improve linting, testing, and GitHub Actions setup (#3583) 2023-04-26 14:13:56 +08:00
recovery_test.go Replace bytes.Buffer with strings.Builder where appropriate (#3347) 2023-01-20 09:51:42 +08:00
response_writer.go add supprt for go1.20 http.rwUnwrapper to gin.responseWriter (#3489) 2023-02-12 13:01:43 +08:00
response_writer_test.go test(render): increased unit tests coverage (#3691) 2023-08-12 22:21:56 +08:00
routergroup.go chore(router): match method added to routergroup for multiple HTTP methods supporting (#3464) 2023-02-06 15:46:42 +08:00
routergroup_test.go chore(router): match method added to routergroup for multiple HTTP methods supporting (#3464) 2023-02-06 15:46:42 +08:00
routes_test.go fix(tree): correctly expand the capacity of params (#3502) 2023-12-07 08:38:55 +08:00
test_helpers.go fix(engine): missing route params for CreateTestContext (#2778) (#2803) 2022-11-06 17:08:11 +08:00
tree.go fix(tree): correctly expand the capacity of params (#3502) 2023-12-07 08:38:55 +08:00
tree_test.go fix(tree): correctly expand the capacity of params (#3502) 2023-12-07 08:38:55 +08:00
utils.go chore: support min go version 1.18 (#3511) 2023-03-01 10:03:48 +08:00
utils_test.go chore: update go.mod and remove space from copyright (#3158) 2022-05-28 10:42:28 +08:00
version.go Ready release gin 1.9.1 (by: thinkerou) (#3630) 2023-06-01 10:26:20 +08:00

README.md

Gin Web Framework

Build Status codecov Go Report Card GoDoc Sourcegraph Open Source Helpers Release TODOs

Gin is a web framework written in Go. It features a martini-like API with performance that is 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

Getting started

Prerequisites

  • Go: any one of the three latest major releases (we test it with these).

Getting Gin

With Go module support, simply add the following import

import "github.com/gin-gonic/gin"

to your code, and then go [build|run|test] will automatically fetch the necessary dependencies.

Otherwise, run the following Go command to install the gin package:

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

Running Gin

First you need to import Gin package for using Gin, one simplest example likes the follow example.go:

package main

import (
  "net/http"

  "github.com/gin-gonic/gin"
)

func main() {
  r := gin.Default()
  r.GET("/ping", func(c *gin.Context) {
    c.JSON(http.StatusOK, gin.H{
      "message": "pong",
    })
  })
  r.Run() // listen and serve on 0.0.0.0:8080 (for windows "localhost: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

Learn more examples

Quick Start

Learn and practice more examples, please read the Gin Quick Start which includes API examples and builds tag.

Examples

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

Documentation

See API documentation and descriptions for package.

All documentation is available on the Gin website.

Articles about Gin

A curated list of awesome Gin framework.

Benchmarks

Gin uses a custom version of HttpRouter, see all benchmarks details.

Benchmark name (1) (2) (3) (4)
BenchmarkGin_GithubAll 43550 27364 ns/op 0 B/op 0 allocs/op
BenchmarkAce_GithubAll 40543 29670 ns/op 0 B/op 0 allocs/op
BenchmarkAero_GithubAll 57632 20648 ns/op 0 B/op 0 allocs/op
BenchmarkBear_GithubAll 9234 216179 ns/op 86448 B/op 943 allocs/op
BenchmarkBeego_GithubAll 7407 243496 ns/op 71456 B/op 609 allocs/op
BenchmarkBone_GithubAll 420 2922835 ns/op 720160 B/op 8620 allocs/op
BenchmarkChi_GithubAll 7620 238331 ns/op 87696 B/op 609 allocs/op
BenchmarkDenco_GithubAll 18355 64494 ns/op 20224 B/op 167 allocs/op
BenchmarkEcho_GithubAll 31251 38479 ns/op 0 B/op 0 allocs/op
BenchmarkGocraftWeb_GithubAll 4117 300062 ns/op 131656 B/op 1686 allocs/op
BenchmarkGoji_GithubAll 3274 416158 ns/op 56112 B/op 334 allocs/op
BenchmarkGojiv2_GithubAll 1402 870518 ns/op 352720 B/op 4321 allocs/op
BenchmarkGoJsonRest_GithubAll 2976 401507 ns/op 134371 B/op 2737 allocs/op
BenchmarkGoRestful_GithubAll 410 2913158 ns/op 910144 B/op 2938 allocs/op
BenchmarkGorillaMux_GithubAll 346 3384987 ns/op 251650 B/op 1994 allocs/op
BenchmarkGowwwRouter_GithubAll 10000 143025 ns/op 72144 B/op 501 allocs/op
BenchmarkHttpRouter_GithubAll 55938 21360 ns/op 0 B/op 0 allocs/op
BenchmarkHttpTreeMux_GithubAll 10000 153944 ns/op 65856 B/op 671 allocs/op
BenchmarkKocha_GithubAll 10000 106315 ns/op 23304 B/op 843 allocs/op
BenchmarkLARS_GithubAll 47779 25084 ns/op 0 B/op 0 allocs/op
BenchmarkMacaron_GithubAll 3266 371907 ns/op 149409 B/op 1624 allocs/op
BenchmarkMartini_GithubAll 331 3444706 ns/op 226551 B/op 2325 allocs/op
BenchmarkPat_GithubAll 273 4381818 ns/op 1483152 B/op 26963 allocs/op
BenchmarkPossum_GithubAll 10000 164367 ns/op 84448 B/op 609 allocs/op
BenchmarkR2router_GithubAll 10000 160220 ns/op 77328 B/op 979 allocs/op
BenchmarkRivet_GithubAll 14625 82453 ns/op 16272 B/op 167 allocs/op
BenchmarkTango_GithubAll 6255 279611 ns/op 63826 B/op 1618 allocs/op
BenchmarkTigerTonic_GithubAll 2008 687874 ns/op 193856 B/op 4474 allocs/op
BenchmarkTraffic_GithubAll 355 3478508 ns/op 820744 B/op 14114 allocs/op
BenchmarkVulcan_GithubAll 6885 193333 ns/op 19894 B/op 609 allocs/op
  • (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.

Users

Awesome project lists using Gin web framework.

  • gorush: A push notification server written in Go.
  • fnproject: The container native, cloud agnostic serverless platform.
  • photoprism: Personal photo management powered by Go and Google TensorFlow.
  • lura: Ultra performant API Gateway with middlewares.
  • picfit: An image resizing server written in Go.
  • dkron: Distributed, fault tolerant job scheduling system.

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.