Gin 使用示例(八):自定义 HTTP 服务器配置


可以直接使用 http.ListenAndServe() 来配置监听地址和端口以及路由器:

func main() {
  router := gin.Default()
  http.ListenAndServe(":8080", router)
}

或者通过下面这种方式来自定义 HTTP 服务器:

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

  s := &http.Server{
    Addr:           ":8080",
    Handler:        router,
    ReadTimeout:    10 * time.Second,
    WriteTimeout:   10 * time.Second,
    MaxHeaderBytes: 1 << 20,
  }
  s.ListenAndServe()
}

点赞 取消点赞 收藏 取消收藏

<< 上一篇: Gin 使用示例(七):控制日志输出颜色

>> 下一篇: Gin 使用示例(九):自定义日志格式