package serve

import (
	"log"
	"net"
	"net/http"
	"os"
	"os/signal"
)

func Serve(port, socket string, handler http.Handler) {
	if socket == "" {
		Port(port, handler)
	} else {
		Socket(socket, handler)
	}
}

func Socket(socket string, handler http.Handler) {
	l, err := net.Listen("unix", socket)
	if err != nil {
		log.Println(err)
		return
	}

	defer l.Close()
	defer os.Remove(socket)

	go func() {
		log.Println("listening on", socket)
		if err := http.Serve(l, handler); err != nil {
			log.Println(err)
		}
	}()

	catchInterrupt()
}

func Port(port string, handler http.Handler) {
	go func() {
		log.Println("listening on port :" + port)
		if err := http.ListenAndServe(":"+port, handler); err != nil {
			log.Println(err)
		}
	}()

	catchInterrupt()
}

func catchInterrupt() {
	c := make(chan os.Signal, 1)
	signal.Notify(c, os.Interrupt, os.Kill)

	s := <-c
	log.Printf("caught %s: shutting down", s)
}

package serve

import (
	"net"
	"net/http"
	"log"
	"os"
	"os/signal"
)

func Serve(port, socket string, handler http.Handler) {
	if socket == "" {
		Port(port, handler)
	} else {
		Socket(socket, handler)
	}
}

func Socket(socket string, handler http.Handler) {
	l, err := net.Listen("unix", socket)
	if err != nil {
		log.Fatal(err)
	}

	defer l.Close()
	defer os.Remove(socket)

	go func() {
		log.Println("listening on", socket)
		log.Fatal(http.Serve(l, handler))
	}()

	catchInterrupt()
}

func Port(port string, handler http.Handler) {
	go func() {
		log.Println("listening on port :" + port)
		log.Fatal(http.ListenAndServe(":"+port, handler))
	}()

	catchInterrupt()
}

func catchInterrupt() {
	c := make(chan os.Signal, 1)
	signal.Notify(c, os.Interrupt, os.Kill)

	s := <-c
	log.Printf("caught %s: shutting down", s)
}

--- 
+++ 
@@ -1,9 +1,9 @@
 package serve
 
 import (
+	"log"
 	"net"
 	"net/http"
-	"log"
 	"os"
 	"os/signal"
 )
@@ -19,7 +19,8 @@
 func Socket(socket string, handler http.Handler) {
 	l, err := net.Listen("unix", socket)
 	if err != nil {
-		log.Fatal(err)
+		log.Println(err)
+		return
 	}
 
 	defer l.Close()
@@ -27,7 +28,9 @@
 
 	go func() {
 		log.Println("listening on", socket)
-		log.Fatal(http.Serve(l, handler))
+		if err := http.Serve(l, handler); err != nil {
+			log.Println(err)
+		}
 	}()
 
 	catchInterrupt()
@@ -36,7 +39,9 @@
 func Port(port string, handler http.Handler) {
 	go func() {
 		log.Println("listening on port :" + port)
-		log.Fatal(http.ListenAndServe(":"+port, handler))
+		if err := http.ListenAndServe(":"+port, handler); err != nil {
+			log.Println(err)
+		}
 	}()
 
 	catchInterrupt()
Replace log.Fatal usages with Println then return
