Learn Go
  • 目录
  • Go 标准库
    • Go 命令行工具flag
    • Go http 库
    • 加密解密
    • Go 解析json
    • Go socket
  • 常用第三方库
    • Go 连接ssh服务器
    • Go 连接snmp获取数据
    • Go websocket 使用
  • Go 优秀开源框架
    • gorm 数据库orm
    • Go web框架gin
      • 快速入门
      • URL中的参数
      • 查询URL中字符串参数
      • 请求方法
      • Multipart/Urlencoded 格式表单
      • 参数和表单的混合
      • Map 格式的 querystring postform 参数
      • 文件上传
      • 路由分组
      • 日志写入文件
      • 后台验证
      • 输出格式
      • 文件服务器
      • 从其他网站拉取内容
      • HTML
      • 使用Goroutines
      • 自定义http配置
      • 支持Let's Encrypt
      • 多个http
      • 优雅的关闭
      • gin 结合jwt
Powered by GitBook
On this page

Was this helpful?

  1. Go 优秀开源框架
  2. Go web框架gin

自定义http配置

自定义http配置

直接使用http.ListenAndServe()

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

或者是

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()
}
Previous使用GoroutinesNext支持Let's Encrypt

Last updated 5 years ago

Was this helpful?