go_reuseport

Brings SO_REUSEPORT into your Go server

  • 所有者: kavu/go_reuseport
  • 平台:
  • 许可证: MIT License
  • 分类:
  • 主题:
    go
  • 喜欢:
    0
      比较:

Github星跟踪图

GO_REUSEPORT

Build Status
codecov
GoDoc

GO_REUSEPORT is a little expirement to create a net.Listener that supports SO_REUSEPORT socket option.

For now, Darwin and Linux (from 3.9) systems are supported. I'll be pleased if you'll test other systems and tell me the results.
documentation on godoc.org.

Example

package main

import (
  "fmt"
  "html"
  "net/http"
  "os"
  "runtime"
  "github.com/kavu/go_reuseport"
)

func main() {
  listener, err := reuseport.Listen("tcp", "localhost:8881")
  if err != nil {
    panic(err)
  }
  defer listener.Close()

  server := &http.Server{}
  http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
    fmt.Println(os.Getgid())
    fmt.Fprintf(w, "Hello, %q\n", html.EscapeString(r.URL.Path))
  })

  panic(server.Serve(listener))
}

Now you can run several instances of this tiny server without Address already in use errors.

Thanks

Inspired by Artur Siekielski post about SO_REUSEPORT.

主要指标

概览
名称与所有者kavu/go_reuseport
主编程语言Go
编程语言Go (语言数: 3)
平台
许可证MIT License
所有者活动
创建于2014-03-16 20:09:22
推送于2021-04-28 20:14:20
最后一次提交2021-04-28 21:49:04
发布数6
最新版本名称v1.5.0 (发布于 )
第一版名称v1.0.0 (发布于 2016-08-18 18:54:48)
用户参与
星数571
关注者数21
派生数68
提交数64
已启用问题?
问题数12
打开的问题数1
拉请求数20
打开的拉请求数0
关闭的拉请求数4
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?