-
Notifications
You must be signed in to change notification settings - Fork 154
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
how to use with so reuseport option for the http example? #406
Comments
You can set Listen func and NListener like this: package main
import (
"fmt"
"net/http"
"time"
"github.com/lesismal/nbio/nbhttp"
reuseport "github.com/libp2p/go-reuseport"
)
func onEcho(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(time.Now().Format("20060102 15:04:05")))
}
func main() {
mux := &http.ServeMux{}
mux.HandleFunc("/", onEcho)
engine := nbhttp.NewServer(nbhttp.Config{
Network: "tcp",
Addrs: []string{"localhost:8080"},
Listen: reuseport.Listen, // set reuseport listen
// NListener: 2, // how many goroutine to handle Accept for each addr, if not set, 1 goroutine by default
Handler: mux,
})
err := engine.Start()
if err != nil {
fmt.Printf("nbio.Start failed: %v\n", err)
return
}
defer engine.Stop()
<-make(chan int)
} |
amazing! thx. u should put somewhere easier to find :D i cant believe i'm the first to ask this question |
Some other users asked about reuseport before, but in Chinese: I'll do some investment to provide more docs/faq, thx for your feedback bro! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
as titled
The text was updated successfully, but these errors were encountered: