71696267 by astaxie

fix #751

add config ListenTCP4

when user want to listen on the TCP4, because now almost use the ipv4.
but default lister on the ipv6
1 parent 90cff5f0
...@@ -20,13 +20,8 @@ import ( ...@@ -20,13 +20,8 @@ import (
20 "net/http" 20 "net/http"
21 "net/http/fcgi" 21 "net/http/fcgi"
22 "time" 22 "time"
23
24 "github.com/astaxie/beego/context"
25 ) 23 )
26 24
27 // FilterFunc defines filter function type.
28 type FilterFunc func(*context.Context)
29
30 // App defines beego application with a new PatternServeMux. 25 // App defines beego application with a new PatternServeMux.
31 type App struct { 26 type App struct {
32 Handlers *ControllerRegistor 27 Handlers *ControllerRegistor
...@@ -85,7 +80,7 @@ func (app *App) Run() { ...@@ -85,7 +80,7 @@ func (app *App) Run() {
85 if HttpsPort != 0 { 80 if HttpsPort != 0 {
86 app.Server.Addr = fmt.Sprintf("%s:%d", HttpAddr, HttpsPort) 81 app.Server.Addr = fmt.Sprintf("%s:%d", HttpAddr, HttpsPort)
87 } 82 }
88 BeeLogger.Info("Running on %s", app.Server.Addr) 83 BeeLogger.Info("https server Running on %s", app.Server.Addr)
89 err := app.Server.ListenAndServeTLS(HttpCertFile, HttpKeyFile) 84 err := app.Server.ListenAndServeTLS(HttpCertFile, HttpKeyFile)
90 if err != nil { 85 if err != nil {
91 BeeLogger.Critical("ListenAndServeTLS: ", err) 86 BeeLogger.Critical("ListenAndServeTLS: ", err)
...@@ -98,12 +93,29 @@ func (app *App) Run() { ...@@ -98,12 +93,29 @@ func (app *App) Run() {
98 if EnableHttpListen { 93 if EnableHttpListen {
99 go func() { 94 go func() {
100 app.Server.Addr = addr 95 app.Server.Addr = addr
101 BeeLogger.Info("Running on %s", app.Server.Addr) 96 BeeLogger.Info("http server Running on %s", app.Server.Addr)
102 err := app.Server.ListenAndServe() 97 if ListenTCP4 && HttpAddr == "" {
103 if err != nil { 98 ln, err := net.Listen("tcp4", app.Server.Addr)
104 BeeLogger.Critical("ListenAndServe: ", err) 99 if err != nil {
105 time.Sleep(100 * time.Microsecond) 100 BeeLogger.Critical("ListenAndServe: ", err)
106 endRunning <- true 101 time.Sleep(100 * time.Microsecond)
102 endRunning <- true
103 return
104 }
105 err = app.Server.Serve(ln)
106 if err != nil {
107 BeeLogger.Critical("ListenAndServe: ", err)
108 time.Sleep(100 * time.Microsecond)
109 endRunning <- true
110 return
111 }
112 } else {
113 err := app.Server.ListenAndServe()
114 if err != nil {
115 BeeLogger.Critical("ListenAndServe: ", err)
116 time.Sleep(100 * time.Microsecond)
117 endRunning <- true
118 }
107 } 119 }
108 }() 120 }()
109 } 121 }
......
...@@ -40,6 +40,7 @@ var ( ...@@ -40,6 +40,7 @@ var (
40 EnableHttpListen bool 40 EnableHttpListen bool
41 HttpAddr string 41 HttpAddr string
42 HttpPort int 42 HttpPort int
43 ListenTCP4 bool
43 EnableHttpTLS bool 44 EnableHttpTLS bool
44 HttpsPort int 45 HttpsPort int
45 HttpCertFile string 46 HttpCertFile string
...@@ -309,6 +310,10 @@ func ParseConfig() (err error) { ...@@ -309,6 +310,10 @@ func ParseConfig() (err error) {
309 HttpPort = v 310 HttpPort = v
310 } 311 }
311 312
313 if v, err := AppConfig.Bool("ListenTCP4"); err == nil {
314 ListenTCP4 = v
315 }
316
312 if v, err := AppConfig.Bool("EnableHttpListen"); err == nil { 317 if v, err := AppConfig.Bool("EnableHttpListen"); err == nil {
313 EnableHttpListen = v 318 EnableHttpListen = v
314 } 319 }
......
...@@ -14,6 +14,11 @@ ...@@ -14,6 +14,11 @@
14 14
15 package beego 15 package beego
16 16
17 import "github.com/astaxie/beego/context"
18
19 // FilterFunc defines filter function type.
20 type FilterFunc func(*context.Context)
21
17 // FilterRouter defines filter operation before controller handler execution. 22 // FilterRouter defines filter operation before controller handler execution.
18 // it can match patterned url and do filter function when action arrives. 23 // it can match patterned url and do filter function when action arrives.
19 type FilterRouter struct { 24 type FilterRouter struct {
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!