support running with socket

This commit is contained in:
zebozhuang 2015-04-13 00:32:31 +08:00
parent dcad0df8f7
commit 832d3b9ecb

24
gin.go
View File

@ -9,7 +9,9 @@ import (
"github.com/julienschmidt/httprouter"
"html/template"
"math"
"net"
"net/http"
"os"
"sync"
)
@ -21,6 +23,9 @@ const (
MIMEXML2 = "text/xml"
MIMEPlain = "text/plain"
MIMEPOSTForm = "application/x-www-form-urlencoded"
UNIX = "unix"
TCP = "tcp"
)
type (
@ -133,6 +138,25 @@ func (engine *Engine) Run(addr string) {
}
}
func (engine *Engine) RunSocket(addr string) {
debugPrint("Listening and serving HTTP on %s", addr)
os.Remove(addr)
listener, err := net.Listen(UNIX, addr)
if err != nil {
panic(err)
}
os.Chmod(0666)
server := http.Server{Handler: engine}
err = server.Serve(listener)
if err != nil {
listener.Close()
panic(err)
}
listener.Close()
}
func (engine *Engine) RunTLS(addr string, cert string, key string) {
debugPrint("Listening and serving HTTPS on %s", addr)
if err := http.ListenAndServeTLS(addr, cert, key, engine); err != nil {