From fd1f7665a77f3bd062586f0f3b54d4ff9863dd4b Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Wed, 21 Dec 2022 13:02:25 +0900 Subject: Abort fzf if --listen port is unavailable --- src/server.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src/server.go') diff --git a/src/server.go b/src/server.go index eaa314c9..75af23ff 100644 --- a/src/server.go +++ b/src/server.go @@ -16,14 +16,14 @@ const ( httpBadRequest = "HTTP/1.1 400 Bad Request" + crlf ) -func startHttpServer(port int, channel chan []*action) { +func startHttpServer(port int, channel chan []*action) error { if port == 0 { - return + return nil } listener, err := net.Listen("tcp", fmt.Sprintf(":%d", port)) if err != nil { - return + return fmt.Errorf("port not available: %d", port) } go func() { @@ -41,6 +41,8 @@ func startHttpServer(port int, channel chan []*action) { } listener.Close() }() + + return nil } // Here we are writing a simplistic HTTP server without using net/http -- cgit v1.2.3