Gin快速开始

25 阅读1分钟

使用命令:go get github.com/gin-gonic/gin 安装依赖

新建一个main.go文件:

package main

import (
   "github.com/gin-gonic/gin"
   "net/http"
)

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

   engine.LoadHTMLGlob("html/**")
   engine.GET("index", func(context *gin.Context) {
      context.JSON(http.StatusOK, "SAS")
   })

   engine.Run(":8080")
}

浏览器请求:localhost:8080/index

返回:SAS