gin-gonic/gin
Fork: 8029 Star: 79217 (更新于 2024-11-30 04:21:28)
license: MIT
Language: Go .
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.
最后发布版本: v1.10.0 ( 2024-05-07 11:48:51)
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.
Gin's key features are:
- Zero allocation router
- Speed
- Middleware support
- Crash-free
- JSON validation
- Route grouping
- Error management
- Built-in rendering
- Extensible
Getting started
Prerequisites
Gin requires Go version 1.21 or above.
Getting Gin
With Go's module support, go [build|run|test]
automatically fetches the necessary dependencies when you add the import in your code:
import "github.com/gin-gonic/gin"
Alternatively, use go get
:
go get -u github.com/gin-gonic/gin
Running Gin
A basic example:
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")
}
To run the code, use the go run
command, like:
$ go run example.go
Then visit 0.0.0.0:8080/ping
in your browser to see the response!
See more examples
Quick Start
Learn and practice with 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 are available in the Gin examples repository.
Documentation
See the API documentation on go.dev.
The documentation is also available on gin-gonic.com in several languages:
Articles
Benchmarks
Gin uses a custom version of HttpRouter, see all benchmarks.
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
Middleware
You can find many useful Gin middlewares at gin-contrib.
Uses
Here are some awesome projects that are using the Gin web framework.
- gorush: A push notification server.
- fnproject: A container native, cloud agnostic serverless platform.
- photoprism: Personal photo management powered by Google TensorFlow.
- lura: Ultra performant API Gateway with middleware.
- picfit: An image resizing server.
- dkron: Distributed, fault tolerant job scheduling system.
Contributing
Gin is the work of hundreds of contributors. We appreciate your help!
Please see CONTRIBUTING.md for details on submitting patches and the contribution workflow.
最近版本更新:(数据更新于 2024-12-21 05:20:13)
2024-05-07 11:48:51 v1.10.0
2023-06-01 10:33:10 v1.9.1
2023-02-21 17:22:43 v1.9.0
2022-12-22 21:42:12 v1.8.2
2022-06-07 00:03:45 v1.8.1
2022-05-30 15:17:13 v1.8.0
2021-11-24 21:57:57 v1.7.7
2021-11-23 13:28:00 v1.7.6
2021-08-15 16:10:09 v1.7.4
2021-08-03 10:41:22 v1.7.3
主题(topics):
framework, gin, go, middleware, performance, router, server
gin-gonic/gin同语言 Go最近更新仓库
2024-12-21 20:15:12 SagerNet/sing-box
2024-12-19 23:11:24 shadow1ng/fscan
2024-12-19 21:50:56 minio/minio
2024-12-19 10:04:39 istio/istio
2024-12-19 05:39:02 XTLS/Xray-core
2024-12-18 20:11:42 Permify/permify