replace endless with facebook grace package.

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
Bo-Yi Wu
2017-01-01 13:35:56 +08:00
parent daf5a73395
commit 218e3fbddc
4 changed files with 71 additions and 38 deletions

View File

@@ -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