Skip to content
Myr

docs(readme): revamp and expand documentation for clarity and completeness (#4362)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

- Update contributing header to single hash style - Remove deprecated badge and improve project summary wording - Reorganize and clarify feature descriptions and benefits - Restructure getting started and installation instructions for clarity - Expand and annotate the first example application walkthrough - Detail the steps for running the sample application and expected output - Improve guidance on learning resources and example projects - Enhance API reference, documentation links, and tutorial references - Add a clear performance benchmarks section comparing Gin to other frameworks - Expand middleware section with ecosystem highlights and usage details - Create a production usage section listing notable projects using Gin - Revamp contribution section with clearer procedure and encouragement for new contributors

authored by Bo-Yi Wu · committed by GitHub · parent 6ad6205 · Browse files · 2 files+113 added−69 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Trailers

  • Signed-off-by: appleboy <appleboy.tw@gmail.com>

Diff stats

2 files+113 added−69 removed

  • other:+113 added−69 removed

2 files+113 added−69 removed

modified:CONTRIBUTING.md+1 added-1 removed
modified:README.md+112 added-68 removed
7 unmodified lines
8[![Go Reference](https://pkg.go.dev/badge/github.com/gin-gonic/gin?status.svg)](https://pkg.go.dev/github.com/gin-gonic/gin?tab=doc)9[![Sourcegraph](https://sourcegraph.com/github.com/gin-gonic/gin/-/badge.svg)](https://sourcegraph.com/github.com/gin-gonic/gin?badge)10[![Open Source Helpers](https://www.codetriage.com/gin-gonic/gin/badges/users.svg)](https://www.codetriage.com/gin-gonic/gin)11[![Release](https://img.shields.io/github/release/gin-gonic/gin.svg?style=flat-square)](https://github.com/gin-gonic/gin/releases)12[![TODOs](https://badgen.net/https/api.tickgit.com/badgen/github.com/gin-gonic/gin)](https://www.tickgit.com/browse?repo=github.com/gin-gonic/gin)1214Gin is a web framework written in [Go](https://go.dev/). It features a martini-like API with performance that is up to 40 times faster thanks to [httprouter](https://github.com/julienschmidt/httprouter).15If you need performance and good productivity, you will love Gin.13Gin is a high-performance HTTP web framework written in [Go](https://go.dev/). It provides a Martini-like API but with significantly better performance—up to 40 times faster—thanks to [httprouter](https://github.com/julienschmidt/httprouter). Gin is designed for building REST APIs, web applications, and microservices where speed and developer productivity are essential.1417**Gin's key features are:**15**Why choose Gin?**1619- Zero allocation router20- Speed21- Middleware support22- Crash-free23- JSON validation24- Route grouping25- Error management26- Built-in rendering27- Extensible17Gin combines the simplicity of Express.js-style routing with Go's performance characteristics, making it ideal for:1829## Getting started19- Building high-throughput REST APIs20- Developing microservices that need to handle many concurrent requests21- Creating web applications that require fast response times22- Prototyping web services quickly with minimal boilerplate2324**Gin's key features:**2526- **Zero allocation router** - Extremely memory-efficient routing with no heap allocations27- **High performance** - Benchmarks show superior speed compared to other Go web frameworks28- **Middleware support** - Extensible middleware system for authentication, logging, CORS, etc.29- **Crash-free** - Built-in recovery middleware prevents panics from crashing your server30- **JSON validation** - Automatic request/response JSON binding and validation31- **Route grouping** - Organize related routes and apply common middleware32- **Error management** - Centralized error handling and logging33- **Built-in rendering** - Support for JSON, XML, HTML templates, and more34- **Extensible** - Large ecosystem of community middleware and plugins3536## Getting Started3738### Prerequisites3933Gin requires [Go](https://go.dev/) version [1.23](https://go.dev/doc/devel/release#go1.23.0) or above.40- **Go version**: Gin requires [Go](https://go.dev/) version [1.23](https://go.dev/doc/devel/release#go1.23.0) or above41- **Basic Go knowledge**: Familiarity with Go syntax and package management is helpful4235### Getting Gin43### Installation4437With [Go's module support](https://go.dev/wiki/Modules#how-to-use-modules), `go [build|run|test]` automatically fetches the necessary dependencies when you add the import in your code:45With [Go's module support](https://go.dev/wiki/Modules#how-to-use-modules), simply import Gin in your code and Go will automatically fetch it during build:4639```sh47```go48import "github.com/gin-gonic/gin"49```5043Alternatively, use `go get`:51### Your First Gin Application5245```sh46go get -u github.com/gin-gonic/gin47```53Here's a complete example that demonstrates Gin's simplicity:5449### Running Gin5051A basic example:5255```go56package main5758import (
2 unmodified lines
61 "github.com/gin-gonic/gin"62)6364func main() {65 // Create a Gin router with default middleware (logger and recovery)66 r := gin.Default()67 68 // Define a simple GET endpoint69 r.GET("/ping", func(c *gin.Context) {70 // Return JSON response71 c.JSON(http.StatusOK, gin.H{72 "message": "pong",73 })74 })69 r.Run() // listen and serve on 0.0.0.0:8080 (for windows "localhost:8080")75 76 // Start server on port 8080 (default)77 // Server will listen on 0.0.0.0:8080 (localhost:8080 on Windows)78 r.Run()79}80```8173To run the code, use the `go run` command, like:82**Running the application:**8375```sh76go run example.go77```841. Save the code above as `main.go`852. Run the application:8679Then visit [`0.0.0.0:8080/ping`](http://0.0.0.0:8080/ping) in your browser to see the response!87 ```sh88 go run main.go89 ```9081### See more examples913. Open your browser and visit [`http://localhost:8080/ping`](http://localhost:8080/ping)924. You should see: `{"message":"pong"}`9383#### Quick Start94**What this example demonstrates:**9585Learn and practice with the [Gin Quick Start](docs/doc.md), which includes API examples and builds tag.96- Creating a Gin router with default middleware97- Defining HTTP endpoints with simple handler functions98- Returning JSON responses99- Starting an HTTP server10087#### Examples101### Next Steps10289A number of ready-to-run examples demonstrating various use cases of Gin are available in the [Gin examples](https://github.com/gin-gonic/examples) repository.103After running your first Gin application, explore these resources to learn more:10491## Documentation105#### 📚 Learning Resources10693See the [API documentation on go.dev](https://pkg.go.dev/github.com/gin-gonic/gin).107- **[Gin Quick Start Guide](docs/doc.md)** - Comprehensive tutorial with API examples and build configurations108- **[Example Repository](https://github.com/gin-gonic/examples)** - Ready-to-run examples demonstrating various Gin use cases:109 - REST API development110 - Authentication & middleware111 - File uploads and downloads112 - WebSocket connections113 - Template rendering11495The documentation is also available on [gin-gonic.com](https://gin-gonic.com) in several languages:115## 📖 Documentation11697- [English](https://gin-gonic.com/en/docs/)98- [简体中文](https://gin-gonic.com/zh-cn/docs/)99- [繁體中文](https://gin-gonic.com/zh-tw/docs/)100- [日本語](https://gin-gonic.com/ja/docs/)101- [Español](https://gin-gonic.com/es/docs/)102- [한국어](https://gin-gonic.com/ko-kr/docs/)103- [Turkish](https://gin-gonic.com/tr/docs/)104- [Persian](https://gin-gonic.com/fa/docs/)105- [Português](https://gin-gonic.com/pt/docs/)106- [Russian](https://gin-gonic.com/ru/docs/)107- [Indonesian](https://gin-gonic.com/id/docs/)117### API Reference118109### Articles119- **[Go.dev API Documentation](https://pkg.go.dev/github.com/gin-gonic/gin)** - Complete API reference with examples120111- [Tutorial: Developing a RESTful API with Go and Gin](https://go.dev/doc/tutorial/web-service-gin)121### User Guides122113## Benchmarks123The comprehensive documentation is available on [gin-gonic.com](https://gin-gonic.com) in multiple languages:124115Gin uses a custom version of [HttpRouter](https://github.com/julienschmidt/httprouter), [see all benchmarks](/BENCHMARKS.md).125- [English](https://gin-gonic.com/en/docs/) | [简体中文](https://gin-gonic.com/zh-cn/docs/) | [繁體中文](https://gin-gonic.com/zh-tw/docs/)126- [日本語](https://gin-gonic.com/ja/docs/) | [한국어](https://gin-gonic.com/ko-kr/docs/) | [Español](https://gin-gonic.com/es/docs/)127- [Turkish](https://gin-gonic.com/tr/docs/) | [Persian](https://gin-gonic.com/fa/docs/) | [Português](https://gin-gonic.com/pt/docs/)128- [Russian](https://gin-gonic.com/ru/docs/) | [Indonesian](https://gin-gonic.com/id/docs/)129130### Official Tutorials131132- [Go.dev Tutorial: Developing a RESTful API with Go and Gin](https://go.dev/doc/tutorial/web-service-gin)133134## ⚡ Performance Benchmarks135136Gin demonstrates exceptional performance compared to other Go web frameworks. It uses a custom version of [HttpRouter](https://github.com/julienschmidt/httprouter) for maximum efficiency. [View detailed benchmarks →](/BENCHMARKS.md)137138**Gin vs. Other Go Frameworks** (GitHub API routing benchmark):139140| Benchmark name | (1) | (2) | (3) | (4) |141| ------------------------------ | --------: | --------------: | -----------: | --------------: |142| BenchmarkGin_GithubAll | **43550** | **27364 ns/op** | **0 B/op** | **0 allocs/op** |143| BenchmarkAce_GithubAll | 40543 | 29670 ns/op | 0 B/op | 0 allocs/op |
30 unmodified lines
174- (2): Single Repetition Duration (ns/op), lower is better175- (3): Heap Memory (B/op), lower is better176- (4): Average Allocations per Repetition (allocs/op), lower is better177155## Middleware178## 🔌 Middleware Ecosystem179157You can find many useful Gin middlewares at [gin-contrib](https://github.com/gin-contrib) and [gin-gonic/contrib](https://github.com/gin-gonic/contrib).180Gin has a rich ecosystem of middleware for common web development needs. Explore community-contributed middleware:181159## Uses182- **[gin-contrib](https://github.com/gin-contrib)** - Official middleware collection including:183 - Authentication (JWT, Basic Auth, Sessions)184 - CORS, Rate limiting, Compression185 - Logging, Metrics, Tracing186 - Static file serving, Template engines187 188- **[gin-gonic/contrib](https://github.com/gin-gonic/contrib)** - Additional community middleware189161Here are some awesome projects that are using the [Gin](https://github.com/gin-gonic/gin) web framework.190## 🏢 Production Usage191163- [gorush](https://github.com/appleboy/gorush): A push notification server.164- [fnproject](https://github.com/fnproject/fn): A container native, cloud agnostic serverless platform.165- [photoprism](https://github.com/photoprism/photoprism): Personal photo management powered by Google TensorFlow.166- [lura](https://github.com/luraproject/lura): Ultra performant API Gateway with middleware.167- [picfit](https://github.com/thoas/picfit): An image resizing server.168- [dkron](https://github.com/distribworks/dkron): Distributed, fault tolerant job scheduling system.192Gin powers many high-traffic applications and services in production:193170## Contributing194- **[gorush](https://github.com/appleboy/gorush)** - High-performance push notification server195- **[fnproject](https://github.com/fnproject/fn)** - Container-native, serverless platform196- **[photoprism](https://github.com/photoprism/photoprism)** - AI-powered personal photo management197- **[lura](https://github.com/luraproject/lura)** - Ultra-performant API Gateway framework198- **[picfit](https://github.com/thoas/picfit)** - Real-time image processing server199- **[dkron](https://github.com/distribworks/dkron)** - Distributed job scheduling system200172Gin is the work of hundreds of contributors. We appreciate your help!201## 🤝 Contributing202174Please see [CONTRIBUTING.md](CONTRIBUTING.md) for details on submitting patches and the contribution workflow.203Gin is the work of hundreds of contributors from around the world. We welcome and appreciate your contributions!204205### How to Contribute206207- 🐛 **Report bugs** - Help us identify and fix issues208- 💡 **Suggest features** - Share your ideas for improvements209- 📝 **Improve documentation** - Help make our docs clearer210- 🔧 **Submit code** - Fix bugs or implement new features211- 🧪 **Write tests** - Improve our test coverage212213### Getting Started with Contributing2142151. Check out our [CONTRIBUTING.md](CONTRIBUTING.md) for detailed guidelines2162. Join our community discussions and ask questions217218**All contributions are valued and help make Gin better for everyone!**