RunUnix attaches the router to a http.Server and starts listening and serving HTTP requests through the specified unix socket (i.e. a file). Note: this method will block the calling goroutine indefinitely unless an error happens.
(file string)
| 579 | // through the specified unix socket (i.e. a file). |
| 580 | // Note: this method will block the calling goroutine indefinitely unless an error happens. |
| 581 | func (engine *Engine) RunUnix(file string) (err error) { |
| 582 | debugPrint("Listening and serving HTTP on unix:/%s", file) |
| 583 | defer func() { debugPrintError(err) }() |
| 584 | |
| 585 | if engine.isUnsafeTrustedProxies() { |
| 586 | debugPrint("[WARNING] You trusted all proxies, this is NOT safe. We recommend you to set a value.\n" + |
| 587 | "Please check https://github.com/gin-gonic/gin/blob/master/docs/doc.md#dont-trust-all-proxies for details.") |
| 588 | } |
| 589 | |
| 590 | listener, err := net.Listen("unix", file) |
| 591 | if err != nil { |
| 592 | return |
| 593 | } |
| 594 | defer listener.Close() |
| 595 | defer os.Remove(file) |
| 596 | |
| 597 | server := &http.Server{ // #nosec G112 |
| 598 | Handler: engine.Handler(), |
| 599 | } |
| 600 | err = server.Serve(listener) |
| 601 | return |
| 602 | } |
| 603 | |
| 604 | // RunFd attaches the router to a http.Server and starts listening and serving HTTP requests |
| 605 | // through the specified file descriptor. |