From bdfd0a9be120d12e917da80b5718663df90f6254 Mon Sep 17 00:00:00 2001 From: Jan Philipp Timme Date: Sun, 12 May 2019 21:08:27 +0200 Subject: [PATCH] Improve code a bit --- socket.go | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/socket.go b/socket.go index 457bf82..2d7566e 100644 --- a/socket.go +++ b/socket.go @@ -2,19 +2,18 @@ package main import ( "bufio" + "fmt" "net" - "os" ) -func runServer() { +func runServer() error { serverSocket, err := net.Listen("tcp", "127.0.0.1:7777") if err != nil { - logger.Errorf("Could not create listening socket: %s\n", err.Error()) - os.Exit(1) - } else { - logger.Infof("Now listening for incoming connections.\n") - defer serverSocket.Close() + myError := fmt.Errorf("could not create listening socket: %s", err.Error()) + return myError } + logger.Infof("Now listening for incoming connections.\n") + defer serverSocket.Close() for { clientConnection, err := serverSocket.Accept() if err != nil {