diff --git a/cmd/circolog-tail/main.go b/cmd/circolog-tail/main.go index d5d9d9a..7c3fb4b 100644 --- a/cmd/circolog-tail/main.go +++ b/cmd/circolog-tail/main.go @@ -4,6 +4,7 @@ import ( "flag" "fmt" "log" + "net" "net/url" "os" "os/signal" @@ -14,19 +15,36 @@ import ( func main() { addr := flag.String("addr", "localhost:9080", "http service address") + querySocket := flag.String("socket", "", "Path to a unix domain socket for the HTTP server") flag.Parse() - fmt.Println("vim-go") - u := url.URL{Scheme: "ws", Host: *addr, Path: "/ws"} - log.Printf("connecting to %s", u.String()) interrupt := make(chan os.Signal, 1) signal.Notify(interrupt, os.Interrupt) + var d *websocket.Dialer + u := url.URL{Scheme: "ws", + Host: *addr, // ignored in case of -socket; see the Dialer below + Path: "/ws", + } + if *querySocket != "" { + d = &websocket.Dialer{ + NetDial: func(network, addr string) (net.Conn, error) { + return net.Dial("unix", *querySocket) + }, + HandshakeTimeout: 45 * time.Second, // same as DefaultDialer + } - c, _, err := websocket.DefaultDialer.Dial(u.String(), nil) + log.Printf("connecting to %s", *querySocket) + } else { + d = websocket.DefaultDialer + log.Printf("connecting to %s", *addr) + } + + c, _, err := d.Dial(u.String(), nil) if err != nil { log.Fatal("dial:", err) } defer c.Close() + log.Println("connected!", u.String()) done := make(chan struct{})