1
0
mirror of https://github.com/astaxie/beego.git synced 2025-07-03 13:30:19 +00:00

beego:support https & http listen

This commit is contained in:
astaxie
2014-05-20 15:30:17 +08:00
parent 3f4d750dc4
commit 18a02d7d60
4 changed files with 43 additions and 13 deletions

33
app.go
View File

@ -45,6 +45,7 @@ func (app *App) Run() {
err error
l net.Listener
)
endRunning := make(chan bool)
if UseFcgi {
if HttpPort == 0 {
@ -83,18 +84,34 @@ func (app *App) Run() {
ReadTimeout: time.Duration(HttpServerTimeOut) * time.Second,
WriteTimeout: time.Duration(HttpServerTimeOut) * time.Second,
}
if HttpTLS {
err = s.ListenAndServeTLS(HttpCertFile, HttpKeyFile)
} else {
err = s.ListenAndServe()
if EnableHttpTLS {
go func() {
if HttpsPort != 0 {
s.Addr = fmt.Sprintf("%s:%d", HttpAddr, HttpsPort)
}
err := s.ListenAndServeTLS(HttpCertFile, HttpKeyFile)
if err != nil {
BeeLogger.Critical("ListenAndServe: ", err)
time.Sleep(100 * time.Microsecond)
endRunning <- true
}
}()
}
if EnableHttpListen {
go func() {
err := s.ListenAndServe()
if err != nil {
BeeLogger.Critical("ListenAndServe: ", err)
time.Sleep(100 * time.Microsecond)
endRunning <- true
}
}()
}
}
}
if err != nil {
BeeLogger.Critical("ListenAndServe: ", err)
time.Sleep(100 * time.Microsecond)
}
<-endRunning
}
// Router adds a url-patterned controller handler.