From a67134d87efd4d0e2c1f70b8a931ef3e6e09c624 Mon Sep 17 00:00:00 2001 From: George Shammas Date: Wed, 9 Jul 2014 15:21:12 +0000 Subject: [PATCH] Make this a FCGI listener, so we can load it easily behind apache --- main.go | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/main.go b/main.go index 33aaf3c..1b01b67 100644 --- a/main.go +++ b/main.go @@ -4,7 +4,7 @@ import ( "fmt" "net" "net/http" - "os" + "net/http/fcgi" "path" "strings" "time" @@ -12,7 +12,6 @@ import ( "github.com/gin-gonic/gin" ) - // Logger is a simple log handler, out puts in the standard of apache access log common. // See http://httpd.apache.org/docs/2.2/logs.html#accesslog func Logger() gin.HandlerFunc { @@ -95,7 +94,6 @@ func mainHandler(c *gin.Context) { } - // FileServer is a basic file serve handler, this is just here as an example. // gin.Static() should be used instead func FileServer(root string) gin.HandlerFunc { @@ -117,9 +115,20 @@ func main() { r.GET("/:field", mainHandler) r.GET("/", mainHandler) - port := os.Getenv("PORT") - if port == "" { - port = "8080" + // Create a listener for FCGI + fcgi_listen, err := net.Listen("tcp", "127.0.0.1:4000") + if err != nil { + panic(err) } - r.Run(":" + port) + err = fcgi.Serve(fcgi_listen, r) + if err != nil { + panic(err) + } + + //port := os.Getenv("PORT") + //host := os.Getenv("HOST") + //if port == "" { + // port = "8080" + //} + //r.Run(host + ":" + port) }