• 使用 HTTP 方法

    使用 HTTP 方法

    1. func main() {
    2. // 禁用控制台颜色
    3. // gin.DisableConsoleColor()
    4. // 使用默认中间件(logger 和 recovery 中间件)创建 gin 路由
    5. router := gin.Default()
    6. router.GET("/someGet", getting)
    7. router.POST("/somePost", posting)
    8. router.PUT("/somePut", putting)
    9. router.DELETE("/someDelete", deleting)
    10. router.PATCH("/somePatch", patching)
    11. router.HEAD("/someHead", head)
    12. router.OPTIONS("/someOptions", options)
    13. // 默认在 8080 端口启动服务,除非定义了一个 PORT 的环境变量。
    14. router.Run()
    15. // router.Run(":3000") hardcode 端口号
    16. }