c6f90df4e0
- Update `github.com/bytedance/sonic` from v1.11.0 to v1.11.3 - Update `github.com/go-playground/validator/v10` from v10.18.0 to v10.19.0 - Update `github.com/pelletier/go-toml/v2` from v2.1.1 to v2.2.0 - Update `github.com/stretchr/testify` from v1.8.4 to v1.9.0 - Update `golang.org/x/net` from v0.21.0 to v0.22.0 - Update `golang.org/x/crypto` from v0.19.0 to v0.21.0 - Update `golang.org/x/sys` from v0.17.0 to v0.18.0 Signed-off-by: appleboy <appleboy.tw@gmail.com> |
||
---|---|---|
.github | ||
binding | ||
docs | ||
examples | ||
ginS | ||
internal | ||
render | ||
testdata | ||
.gitignore | ||
.golangci.yml | ||
.goreleaser.yaml | ||
auth_test.go | ||
auth.go | ||
AUTHORS.md | ||
benchmarks_test.go | ||
BENCHMARKS.md | ||
CHANGELOG.md | ||
CODE_OF_CONDUCT.md | ||
codecov.yml | ||
context_1.18_test.go | ||
context_1.19_test.go | ||
context_appengine.go | ||
context_test.go | ||
context.go | ||
CONTRIBUTING.md | ||
debug_test.go | ||
debug.go | ||
deprecated_test.go | ||
deprecated.go | ||
doc.go | ||
errors_test.go | ||
errors.go | ||
fs.go | ||
gin_integration_test.go | ||
gin_test.go | ||
gin.go | ||
githubapi_test.go | ||
go.mod | ||
go.sum | ||
LICENSE | ||
logger_test.go | ||
logger.go | ||
Makefile | ||
middleware_test.go | ||
mode_test.go | ||
mode.go | ||
path_test.go | ||
path.go | ||
README.md | ||
recovery_test.go | ||
recovery.go | ||
response_writer_test.go | ||
response_writer.go | ||
routergroup_test.go | ||
routergroup.go | ||
routes_test.go | ||
test_helpers.go | ||
tree_test.go | ||
tree.go | ||
utils_test.go | ||
utils.go | ||
version.go |
Gin Web Framework
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
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.