[tail] unix socket support
This commit is contained in:
parent
a5999adb8d
commit
d380deae37
1 changed files with 22 additions and 4 deletions
|
@ -4,6 +4,7 @@ import (
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
"net"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
|
@ -14,19 +15,36 @@ import (
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
addr := flag.String("addr", "localhost:9080", "http service address")
|
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()
|
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)
|
interrupt := make(chan os.Signal, 1)
|
||||||
signal.Notify(interrupt, os.Interrupt)
|
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 {
|
if err != nil {
|
||||||
log.Fatal("dial:", err)
|
log.Fatal("dial:", err)
|
||||||
}
|
}
|
||||||
defer c.Close()
|
defer c.Close()
|
||||||
|
log.Println("connected!", u.String())
|
||||||
|
|
||||||
done := make(chan struct{})
|
done := make(chan struct{})
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue