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?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?