github.com/go-board/x-go@v0.1.2-0.20220610024734-db1323f6cb15/xnet/xhttp/server.go (about) 1 package xhttp 2 3 import ( 4 "net" 5 "net/http" 6 7 "github.com/go-board/x-go/xnet" 8 ) 9 10 // ServeLimitedServer run on a limited listener which limit maxium concurrency connection. 11 func ServeLimitedServer(server *http.Server, address string, n int) error { 12 ln, err := net.Listen("tcp", address) 13 if err != nil { 14 return err 15 } 16 limitedListener := xnet.LimitedListener(ln, n) 17 return server.Serve(limitedListener) 18 } 19 20 // ServeTLSLimitedServer run on a limited tls listener which limit maxium concurrency connection. 21 func ServeTLSLimitedServer(server *http.Server, address string, n int, certFile string, keyFile string) error { 22 ln, err := net.Listen("tcp", address) 23 if err != nil { 24 return err 25 } 26 limitedListener := xnet.LimitedListener(ln, n) 27 return server.ServeTLS(limitedListener, certFile, keyFile) 28 }