From b8e7a46fc17d3c91cb4f5f090b789fbfef2b232a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B7=B1=E8=93=9D?= Date: Thu, 10 Jan 2013 20:22:00 +0800 Subject: [PATCH] add fcgi support --- beego.go | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/beego.go b/beego.go index b20be7e6..82c53d12 100644 --- a/beego.go +++ b/beego.go @@ -5,7 +5,9 @@ import ( "github.com/astaxie/session" _ "github.com/astaxie/session/providers/memory" "html/template" + "net" "net/http" + "net/http/fcgi" "os" "path" "strconv" @@ -30,6 +32,7 @@ var ( SessionProvider string // default session provider memory SessionName string // sessionName cookie's name SessionGCMaxLifetime int64 // session's gc maxlifetime + UseFcgi bool GlobalSessions *session.Manager //GlobalSessions ) @@ -55,6 +58,7 @@ func init() { SessionProvider = "memory" SessionName = "beegosessionID" SessionGCMaxLifetime = 3600 + UseFcgi = false } else { HttpAddr = AppConfig.String("httpaddr") if v, err := AppConfig.Int("httpport"); err != nil { @@ -109,6 +113,11 @@ func init() { } else { SessionGCMaxLifetime = 3600 } + if ar, err := AppConfig.Bool("usefcgi"); err != nil { + UseFcgi = false + } else { + UseFcgi = ar + } } StaticDir["/static"] = "static" @@ -127,7 +136,16 @@ func NewApp() *App { func (app *App) Run() { addr := fmt.Sprintf("%s:%d", HttpAddr, HttpPort) - err := http.ListenAndServe(addr, app.Handlers) + var err error + if UseFcgi { + l, e := net.Listen("tcp", addr) + if e != nil { + BeeLogger.Fatal("Listen: ", e) + } + err = fcgi.Serve(l, app.Handlers) + } else { + err = http.ListenAndServe(addr, app.Handlers) + } if err != nil { BeeLogger.Fatal("ListenAndServe: ", err) }