replace endless with facebook grace package.
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
@@ -3,7 +3,10 @@
|
||||
package gorush
|
||||
|
||||
import (
|
||||
"github.com/fvbock/endless"
|
||||
"crypto/tls"
|
||||
"net/http"
|
||||
|
||||
"github.com/facebookgo/grace/gracehttp"
|
||||
)
|
||||
|
||||
// RunHTTPServer provide run http or https protocol.
|
||||
@@ -11,9 +14,30 @@ func RunHTTPServer() error {
|
||||
var err error
|
||||
|
||||
if PushConf.Core.SSL && PushConf.Core.CertPath != "" && PushConf.Core.KeyPath != "" {
|
||||
err = endless.ListenAndServeTLS(":"+PushConf.Core.Port, PushConf.Core.CertPath, PushConf.Core.KeyPath, routerEngine())
|
||||
config := &tls.Config{
|
||||
MinVersion: tls.VersionTLS10,
|
||||
}
|
||||
|
||||
if config.NextProtos == nil {
|
||||
config.NextProtos = []string{"http/1.1"}
|
||||
}
|
||||
|
||||
config.Certificates = make([]tls.Certificate, 1)
|
||||
config.Certificates[0], err = tls.LoadX509KeyPair(PushConf.Core.CertPath, PushConf.Core.KeyPath)
|
||||
if err != nil {
|
||||
LogError.Fatal("Failed to load https cert file: ", err)
|
||||
}
|
||||
|
||||
err = gracehttp.Serve(&http.Server{
|
||||
Addr: ":" + PushConf.Core.Port,
|
||||
Handler: routerEngine(),
|
||||
TLSConfig: config,
|
||||
})
|
||||
} else {
|
||||
err = endless.ListenAndServe(":"+PushConf.Core.Port, routerEngine())
|
||||
err = gracehttp.Serve(&http.Server{
|
||||
Addr: ":" + PushConf.Core.Port,
|
||||
Handler: routerEngine(),
|
||||
})
|
||||
}
|
||||
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user