Created
March 25, 2017 01:35
-
-
Save jordanorelli/5ef1833d6f2d16d34c403b4b88f42139 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"log" | |
"net" | |
"net/http" | |
"os" | |
) | |
type rootHandler struct { | |
socket string | |
} | |
func (h rootHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { | |
log.Printf("[%s] %s", h.socket, r.URL.Path) | |
fmt.Fprintf(w, "hi from %s", h.socket) | |
} | |
func listenOnSocket(name string) { | |
os.Remove(name) | |
lis, err := net.Listen("unix", name) | |
if err != nil { | |
log.Fatalf("couldn't listen on unix socket: %v", err) | |
} | |
// lol | |
os.Chmod(name, 0777) | |
log.Printf("unix socket listener: %v", lis) | |
http.Serve(lis, rootHandler{name}) | |
} | |
func main() { | |
go listenOnSocket("/tmp/socket-one") | |
listenOnSocket("/tmp/socket-two") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment