diff --git a/gorush/server.go b/gorush/server.go index bcc55ff..99d6585 100644 --- a/gorush/server.go +++ b/gorush/server.go @@ -3,8 +3,6 @@ package gorush import ( "context" "crypto/tls" - "encoding/base64" - "errors" "fmt" "net/http" @@ -139,66 +137,3 @@ func routerEngine() *gin.Engine { 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("", "") -} diff --git a/gorush/server_normal.go b/gorush/server_normal.go new file mode 100644 index 0000000..a54a925 --- /dev/null +++ b/gorush/server_normal.go @@ -0,0 +1,73 @@ +// +build !lambda + +package gorush + +import ( + "crypto/tls" + "encoding/base64" + "errors" + "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 + } + + 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("", "") +} diff --git a/pipeline.libsonnet b/pipeline.libsonnet index 4d8df41..65e5015 100644 --- a/pipeline.libsonnet +++ b/pipeline.libsonnet @@ -128,6 +128,22 @@ }, }, }, + // { + // name: 'build-push-lambda', + // image: 'golang:1.13', + // pull: 'always', + // environment: { + // CGO_ENABLED: '0', + // }, + // commands: [ + // 'go build -v -tags \'lambda\' -ldflags \'-X main.build=${DRONE_BUILD_NUMBER}\' -a -o release/' + os + '/' + arch + '/lambda/' + name, + // ], + // when: { + // event: { + // exclude: [ 'tag' ], + // }, + // }, + // }, { name: 'build-tag', image: 'golang:1.13',