c6d4eece by astaxie

Merge pull request #8 from xgdapg/master

add fcgi support
2 parents 10e7dc85 b8e7a46f
Showing 1 changed file with 19 additions and 1 deletions
...@@ -5,7 +5,9 @@ import ( ...@@ -5,7 +5,9 @@ import (
5 "github.com/astaxie/session" 5 "github.com/astaxie/session"
6 _ "github.com/astaxie/session/providers/memory" 6 _ "github.com/astaxie/session/providers/memory"
7 "html/template" 7 "html/template"
8 "net"
8 "net/http" 9 "net/http"
10 "net/http/fcgi"
9 "os" 11 "os"
10 "path" 12 "path"
11 "strconv" 13 "strconv"
...@@ -30,6 +32,7 @@ var ( ...@@ -30,6 +32,7 @@ var (
30 SessionProvider string // default session provider memory 32 SessionProvider string // default session provider memory
31 SessionName string // sessionName cookie's name 33 SessionName string // sessionName cookie's name
32 SessionGCMaxLifetime int64 // session's gc maxlifetime 34 SessionGCMaxLifetime int64 // session's gc maxlifetime
35 UseFcgi bool
33 36
34 GlobalSessions *session.Manager //GlobalSessions 37 GlobalSessions *session.Manager //GlobalSessions
35 ) 38 )
...@@ -55,6 +58,7 @@ func init() { ...@@ -55,6 +58,7 @@ func init() {
55 SessionProvider = "memory" 58 SessionProvider = "memory"
56 SessionName = "beegosessionID" 59 SessionName = "beegosessionID"
57 SessionGCMaxLifetime = 3600 60 SessionGCMaxLifetime = 3600
61 UseFcgi = false
58 } else { 62 } else {
59 HttpAddr = AppConfig.String("httpaddr") 63 HttpAddr = AppConfig.String("httpaddr")
60 if v, err := AppConfig.Int("httpport"); err != nil { 64 if v, err := AppConfig.Int("httpport"); err != nil {
...@@ -109,6 +113,11 @@ func init() { ...@@ -109,6 +113,11 @@ func init() {
109 } else { 113 } else {
110 SessionGCMaxLifetime = 3600 114 SessionGCMaxLifetime = 3600
111 } 115 }
116 if ar, err := AppConfig.Bool("usefcgi"); err != nil {
117 UseFcgi = false
118 } else {
119 UseFcgi = ar
120 }
112 } 121 }
113 StaticDir["/static"] = "static" 122 StaticDir["/static"] = "static"
114 123
...@@ -127,7 +136,16 @@ func NewApp() *App { ...@@ -127,7 +136,16 @@ func NewApp() *App {
127 136
128 func (app *App) Run() { 137 func (app *App) Run() {
129 addr := fmt.Sprintf("%s:%d", HttpAddr, HttpPort) 138 addr := fmt.Sprintf("%s:%d", HttpAddr, HttpPort)
130 err := http.ListenAndServe(addr, app.Handlers) 139 var err error
140 if UseFcgi {
141 l, e := net.Listen("tcp", addr)
142 if e != nil {
143 BeeLogger.Fatal("Listen: ", e)
144 }
145 err = fcgi.Serve(l, app.Handlers)
146 } else {
147 err = http.ListenAndServe(addr, app.Handlers)
148 }
131 if err != nil { 149 if err != nil {
132 BeeLogger.Fatal("ListenAndServe: ", err) 150 BeeLogger.Fatal("ListenAndServe: ", err)
133 } 151 }
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!