1. package main
    2. import (
    3. "net/http"
    4. "github.com/gin-gonic/gin"
    5. )
    6. func main() {
    7. app := gin.Default()
    8. app.GET("/user.json", func(c *gin.Context) {
    9. c.Header("Content-Type", "application/json")
    10. c.Header("Access-Control-Allow-Origin", "*")
    11. c.Header("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE")
    12. c.Header("Access-Control-Allow-Headers", "Action, Module, X-PINGOTHER, Content-Type, Content-Disposition")
    13. app.LoadHTMLGlob("./data/*") // 静态资源所属文件夹
    14. c.HTML(http.StatusOK, "user.json", nil) // 文件名 user.json
    15. })
    16. //
    17. app.Run(":80") // Run("里面不指定端口号默认为8080")
    18. }