Gin 是一个用 Go 语言开发的 Web 框架,提供类 Martini 的 API,但是性能更好。因为有了 [httprouter](http://www.oschina.net/p/httprouter) 性能提升了 40 倍之多。
![Gin console logger](http://static.oschina.net/uploads/img/201505/15073359_kaF3.jpg)
<pre class="brush:shell;toolbar: true; auto-links: false;">$ cat test.go</pre>
<pre class="brush:cpp ;toolbar: true; auto-links: false;">package main
import (
"net/http"
"github.com/gin-gonic/gin"
)
func main() {
router := gin.Default()
router.GET("/", func(c *gin.Context) {
c.String(http.StatusOK, "hello world")
})
router.GET("/ping", func(c *gin.Context) {
c.String(http.StatusOK, "pong")
})
router.POST("/submit", func(c *gin.Context) {
c.String(http.StatusUnauthorized, "not authorized")
})
router.PUT("/error", func(c *gin.Context) {
c.String(http.StatusInternalServerError, "an error happened :(")
})
router.Run(":8080")
}</pre>