chore: remove facebook graceful shutdown package. (#408)

* chore: remove facebook graceful shutdown package.

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
Bo-Yi Wu 2019-04-29 11:33:27 +08:00 committed by GitHub
parent c08f593a86
commit 55ff87f96f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 65 additions and 121 deletions

8
go.mod
View File

@ -18,14 +18,6 @@ require (
github.com/dgrijalva/jwt-go v3.1.0+incompatible // indirect github.com/dgrijalva/jwt-go v3.1.0+incompatible // indirect
github.com/dgryski/go-farm v0.0.0-20180109070241-2de33835d102 // indirect github.com/dgryski/go-farm v0.0.0-20180109070241-2de33835d102 // indirect
github.com/emirpasic/gods v0.0.0-20170204130913-fc3e4a43ff31 // indirect github.com/emirpasic/gods v0.0.0-20170204130913-fc3e4a43ff31 // indirect
github.com/facebookgo/clock v0.0.0-20150410010913-600d898af40a // indirect
github.com/facebookgo/ensure v0.0.0-20160127193407-b4ab57deab51 // indirect
github.com/facebookgo/freeport v0.0.0-20150612182905-d4adf43b75b9 // indirect
github.com/facebookgo/grace v0.0.0-20170218225239-4afe952a37a4
github.com/facebookgo/httpdown v0.0.0-20160323221027-a3b1354551a2 // indirect
github.com/facebookgo/stack v0.0.0-20160209184415-751773369052 // indirect
github.com/facebookgo/stats v0.0.0-20151006221625-1b76add642e4 // indirect
github.com/facebookgo/subset v0.0.0-20150612182917-8dac2c3c4870 // indirect
github.com/gin-contrib/sse v0.0.0-20170109093832-22d885f9ecc7 // indirect github.com/gin-contrib/sse v0.0.0-20170109093832-22d885f9ecc7 // indirect
github.com/gin-gonic/gin v0.0.0-20170929084810-b8b68314faa0 github.com/gin-gonic/gin v0.0.0-20170929084810-b8b68314faa0
github.com/gogo/protobuf v1.1.1 github.com/gogo/protobuf v1.1.1

18
go.sum
View File

@ -34,22 +34,6 @@ github.com/dgryski/go-farm v0.0.0-20180109070241-2de33835d102 h1:afESQBXJEnj3fu+
github.com/dgryski/go-farm v0.0.0-20180109070241-2de33835d102/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw= github.com/dgryski/go-farm v0.0.0-20180109070241-2de33835d102/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw=
github.com/emirpasic/gods v0.0.0-20170204130913-fc3e4a43ff31 h1:l2nU4fk8IgsxoSLC2Tj+UrqiZXlFfZGMAj04oMJN+VU= github.com/emirpasic/gods v0.0.0-20170204130913-fc3e4a43ff31 h1:l2nU4fk8IgsxoSLC2Tj+UrqiZXlFfZGMAj04oMJN+VU=
github.com/emirpasic/gods v0.0.0-20170204130913-fc3e4a43ff31/go.mod h1:YfzfFFoVP/catgzJb4IKIqXjX78Ha8FMSDh3ymbK86o= github.com/emirpasic/gods v0.0.0-20170204130913-fc3e4a43ff31/go.mod h1:YfzfFFoVP/catgzJb4IKIqXjX78Ha8FMSDh3ymbK86o=
github.com/facebookgo/clock v0.0.0-20150410010913-600d898af40a h1:yDWHCSQ40h88yih2JAcL6Ls/kVkSE8GFACTGVnMPruw=
github.com/facebookgo/clock v0.0.0-20150410010913-600d898af40a/go.mod h1:7Ga40egUymuWXxAe151lTNnCv97MddSOVsjpPPkityA=
github.com/facebookgo/ensure v0.0.0-20160127193407-b4ab57deab51 h1:0JZ+dUmQeA8IIVUMzysrX4/AKuQwWhV2dYQuPZdvdSQ=
github.com/facebookgo/ensure v0.0.0-20160127193407-b4ab57deab51/go.mod h1:Yg+htXGokKKdzcwhuNDwVvN+uBxDGXJ7G/VN1d8fa64=
github.com/facebookgo/freeport v0.0.0-20150612182905-d4adf43b75b9 h1:wWke/RUCl7VRjQhwPlR/v0glZXNYzBHdNUzf/Am2Nmg=
github.com/facebookgo/freeport v0.0.0-20150612182905-d4adf43b75b9/go.mod h1:uPmAp6Sws4L7+Q/OokbWDAK1ibXYhB3PXFP1kol5hPg=
github.com/facebookgo/grace v0.0.0-20170218225239-4afe952a37a4 h1:c8bY3vJpaia8nrZANEBY8yL7rGg7TSit8O1eAJe4hbo=
github.com/facebookgo/grace v0.0.0-20170218225239-4afe952a37a4/go.mod h1:KigFdumBXUPSwzLDbeuzyt0elrL7+CP7TKuhrhT4bcU=
github.com/facebookgo/httpdown v0.0.0-20160323221027-a3b1354551a2 h1:3Zvf9wRhl1cOhckN1oRGWPOkIhOketmEcrQ4TeFAoR4=
github.com/facebookgo/httpdown v0.0.0-20160323221027-a3b1354551a2/go.mod h1:TUV/fX3XrTtBQb5+ttSUJzcFgLNpILONFTKmBuk5RSw=
github.com/facebookgo/stack v0.0.0-20160209184415-751773369052 h1:JWuenKqqX8nojtoVVWjGfOF9635RETekkoH6Cc9SX0A=
github.com/facebookgo/stack v0.0.0-20160209184415-751773369052/go.mod h1:UbMTZqLaRiH3MsBH8va0n7s1pQYcu3uTb8G4tygF4Zg=
github.com/facebookgo/stats v0.0.0-20151006221625-1b76add642e4 h1:0YtRCqIZs2+Tz49QuH6cJVw/IFqzo39gEqZ0iYLxD2M=
github.com/facebookgo/stats v0.0.0-20151006221625-1b76add642e4/go.mod h1:vsJz7uE339KUCpBXx3JAJzSRH7Uk4iGGyJzR529qDIA=
github.com/facebookgo/subset v0.0.0-20150612182917-8dac2c3c4870 h1:E2s37DuLxFhQDg5gKsWoLBOB0n+ZW8s599zru8FJ2/Y=
github.com/facebookgo/subset v0.0.0-20150612182917-8dac2c3c4870/go.mod h1:5tD+neXqOorC30/tWg0LCSkrqj/AR6gu8yY8/fpw1q0=
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/gin-contrib/sse v0.0.0-20170109093832-22d885f9ecc7 h1:AzN37oI0cOS+cougNAV9szl6CVoj2RYwzS3DpUQNtlY= github.com/gin-contrib/sse v0.0.0-20170109093832-22d885f9ecc7 h1:AzN37oI0cOS+cougNAV9szl6CVoj2RYwzS3DpUQNtlY=
@ -130,8 +114,6 @@ github.com/stretchr/testify v0.0.0-20170130113145-4d4bfba8f1d1 h1:Zx8Rp9ozC4FPFx
github.com/stretchr/testify v0.0.0-20170130113145-4d4bfba8f1d1/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v0.0.0-20170130113145-4d4bfba8f1d1/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/syndtr/goleveldb v0.0.0-20161227110519-23851d93a229 h1:arXQNTPyszL9q5nmGtSXyGocRDQRxdtoSS25nZgPvCI= github.com/syndtr/goleveldb v0.0.0-20161227110519-23851d93a229 h1:arXQNTPyszL9q5nmGtSXyGocRDQRxdtoSS25nZgPvCI=
github.com/syndtr/goleveldb v0.0.0-20161227110519-23851d93a229/go.mod h1:Z4AUp2Km+PwemOoO/VB5AOx9XSsIItzFjoJlOSiYmn0= github.com/syndtr/goleveldb v0.0.0-20161227110519-23851d93a229/go.mod h1:Z4AUp2Km+PwemOoO/VB5AOx9XSsIItzFjoJlOSiYmn0=
github.com/thoas/stats v0.0.0-20160726120248-152b5d051953 h1:PD6HdaGc9tn2a8W/33zxcA6DTq1D1K0O/PKWOGz3Lxo=
github.com/thoas/stats v0.0.0-20160726120248-152b5d051953/go.mod h1:GkZsNBOco11YY68OnXUARbSl26IOXXAeYf6ZKmSZR2M=
github.com/thoas/stats v0.0.0-20181218120333-e97827ebd7ca h1:Ju3LQGLQHCUv1yB2WwB1/uXHL+8SfF4E8qm/iSCQV0Q= github.com/thoas/stats v0.0.0-20181218120333-e97827ebd7ca h1:Ju3LQGLQHCUv1yB2WwB1/uXHL+8SfF4E8qm/iSCQV0Q=
github.com/thoas/stats v0.0.0-20181218120333-e97827ebd7ca/go.mod h1:GkZsNBOco11YY68OnXUARbSl26IOXXAeYf6ZKmSZR2M= github.com/thoas/stats v0.0.0-20181218120333-e97827ebd7ca/go.mod h1:GkZsNBOco11YY68OnXUARbSl26IOXXAeYf6ZKmSZR2M=
github.com/tidwall/btree v0.0.0-20170113224114-9876f1454cf0 h1:QnyrPZZvPmR0AtJCxxfCtI1qN+fYpKTKJ/5opWmZ34k= github.com/tidwall/btree v0.0.0-20170113224114-9876f1454cf0 h1:QnyrPZZvPmR0AtJCxxfCtI1qN+fYpKTKJ/5opWmZ34k=

View File

@ -2,6 +2,8 @@ package gorush
import ( import (
"crypto/tls" "crypto/tls"
"encoding/base64"
"errors"
"fmt" "fmt"
"net/http" "net/http"
@ -124,3 +126,66 @@ func routerEngine() *gin.Engine {
return r return r
} }
// RunHTTPServer provide run http or https protocol.
func RunHTTPServer() (err error) {
if !PushConf.Core.Enabled {
LogAccess.Debug("httpd server is disabled.")
return nil
}
server := &http.Server{
Addr: PushConf.Core.Address + ":" + PushConf.Core.Port,
Handler: routerEngine(),
}
LogAccess.Debug("HTTPD server is running on " + PushConf.Core.Port + " port.")
if PushConf.Core.AutoTLS.Enabled {
return startServer(autoTLSServer())
} else if PushConf.Core.SSL {
config := &tls.Config{
MinVersion: tls.VersionTLS10,
}
if config.NextProtos == nil {
config.NextProtos = []string{"http/1.1"}
}
config.Certificates = make([]tls.Certificate, 1)
if PushConf.Core.CertPath != "" && PushConf.Core.KeyPath != "" {
config.Certificates[0], err = tls.LoadX509KeyPair(PushConf.Core.CertPath, PushConf.Core.KeyPath)
if err != nil {
LogError.Error("Failed to load https cert file: ", err)
return err
}
} else if PushConf.Core.CertBase64 != "" && PushConf.Core.KeyBase64 != "" {
cert, err := base64.StdEncoding.DecodeString(PushConf.Core.CertBase64)
if err != nil {
LogError.Error("base64 decode error:", err.Error())
return err
}
key, err := base64.StdEncoding.DecodeString(PushConf.Core.KeyBase64)
if err != nil {
LogError.Error("base64 decode error:", err.Error())
return err
}
if config.Certificates[0], err = tls.X509KeyPair(cert, key); err != nil {
LogError.Error("tls key pair error:", err.Error())
return err
}
} else {
return errors.New("missing https cert config")
}
server.TLSConfig = config
}
return startServer(server)
}
func startServer(s *http.Server) error {
if s.TLSConfig == nil {
return s.ListenAndServe()
}
return s.ListenAndServeTLS("", "")
}

View File

@ -1,69 +0,0 @@
// +build !windows,!lambda
package gorush
import (
"crypto/tls"
"encoding/base64"
"errors"
"net/http"
"github.com/facebookgo/grace/gracehttp"
)
// RunHTTPServer provide run http or https protocol.
func RunHTTPServer() (err error) {
if !PushConf.Core.Enabled {
LogAccess.Debug("httpd server is disabled.")
return nil
}
LogAccess.Debug("HTTPD server is running on " + PushConf.Core.Port + " port.")
if PushConf.Core.AutoTLS.Enabled {
err = gracehttp.Serve(autoTLSServer())
} else if PushConf.Core.SSL {
config := &tls.Config{
MinVersion: tls.VersionTLS10,
}
if config.NextProtos == nil {
config.NextProtos = []string{"http/1.1"}
}
config.Certificates = make([]tls.Certificate, 1)
if PushConf.Core.CertPath != "" && PushConf.Core.KeyPath != "" {
config.Certificates[0], err = tls.LoadX509KeyPair(PushConf.Core.CertPath, PushConf.Core.KeyPath)
if err != nil {
LogError.Error("Failed to load https cert file: ", err)
return err
}
} else if PushConf.Core.CertBase64 != "" && PushConf.Core.KeyBase64 != "" {
cert, err := base64.StdEncoding.DecodeString(PushConf.Core.CertBase64)
if err != nil {
LogError.Error("base64 decode error:", err.Error())
return err
}
key, err := base64.StdEncoding.DecodeString(PushConf.Core.KeyBase64)
if err != nil {
LogError.Error("base64 decode error:", err.Error())
return err
}
config.Certificates[0], err = tls.X509KeyPair(cert, key)
} else {
return errors.New("missing https cert config")
}
err = gracehttp.Serve(&http.Server{
Addr: PushConf.Core.Address + ":" + PushConf.Core.Port,
Handler: routerEngine(),
TLSConfig: config,
})
} else {
err = gracehttp.Serve(&http.Server{
Addr: PushConf.Core.Address + ":" + PushConf.Core.Port,
Handler: routerEngine(),
})
}
return
}

View File

@ -1,26 +0,0 @@
// +build windows,!lambda
package gorush
import (
"net/http"
)
// RunHTTPServer provide run http or https protocol.
func RunHTTPServer() (err error) {
if !PushConf.Core.Enabled {
LogAccess.Debug("httpd server is disabled.")
return nil
}
if PushConf.Core.AutoTLS.Enabled {
s := autoTLSServer()
err = s.ListenAndServeTLS("", "")
} else if PushConf.Core.SSL && PushConf.Core.CertPath != "" && PushConf.Core.KeyPath != "" {
err = http.ListenAndServeTLS(PushConf.Core.Address+":"+PushConf.Core.Port, PushConf.Core.CertPath, PushConf.Core.KeyPath, routerEngine())
} else {
err = http.ListenAndServe(PushConf.Core.Address+":"+PushConf.Core.Port, routerEngine())
}
return
}