Gin 是一个用 Go (Golang) 编写的 HTTP Web 框架。 它具有类似 Martini 的 API,但性能比 Martini 快 40 倍。

文档

安装

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

代码示例 main.go

package main

import (
"net/http"

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

func main() {
app := gin.Default()

app.GET("/", func(ctx *gin.Context) {
ctx.String(http.StatusOK, "hello")
})

// 监听并在 http://127.0.0.1:8080 上启动服务
app.Run()
}

启动服务

$ go run main.go

返回示例

Golang:gin-gonic/gin一个用 Go (Golang) 编写的 HTTP Web 框架_github