Unix sockets support
This commit is contained in:
parent
f9952b0545
commit
cd6e95f0e4
21
gin.go
21
gin.go
@ -6,7 +6,9 @@ package gin
|
||||
|
||||
import (
|
||||
"html/template"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"sync"
|
||||
|
||||
"github.com/gin-gonic/gin/binding"
|
||||
@ -159,7 +161,7 @@ func (engine *Engine) handle(method, path string, handlers HandlersChain) {
|
||||
|
||||
func (engine *Engine) Run(addr string) (err error) {
|
||||
debugPrint("Listening and serving HTTP on %s\n", addr)
|
||||
defer debugPrintError(err)
|
||||
defer func() { debugPrintError(err) }()
|
||||
|
||||
err = http.ListenAndServe(addr, engine)
|
||||
return
|
||||
@ -167,12 +169,27 @@ func (engine *Engine) Run(addr string) (err error) {
|
||||
|
||||
func (engine *Engine) RunTLS(addr string, cert string, key string) (err error) {
|
||||
debugPrint("Listening and serving HTTPS on %s\n", addr)
|
||||
defer debugPrintError(err)
|
||||
defer func() { debugPrintError(err) }()
|
||||
|
||||
err = http.ListenAndServe(addr, engine)
|
||||
return
|
||||
}
|
||||
|
||||
func (engine *Engine) RunUnix(file string) (err error) {
|
||||
debugPrint("Listening and serving HTTP on unix:/%s", file)
|
||||
defer func() { debugPrintError(err) }()
|
||||
|
||||
os.Remove(file)
|
||||
listener, err2 := net.Listen("unix", file)
|
||||
err = err2
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
defer listener.Close()
|
||||
err = http.Serve(listener, engine)
|
||||
return
|
||||
}
|
||||
|
||||
// ServeHTTP makes the router implement the http.Handler interface.
|
||||
func (engine *Engine) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
||||
c := engine.getcontext(w, req)
|
||||
|
Loading…
Reference in New Issue
Block a user