Add -addr flag, include ability to use unix path
This commit is contained in:
18
main.go
18
main.go
@ -1,8 +1,10 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"flag"
|
||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/posteo/go-agentx"
|
"github.com/posteo/go-agentx"
|
||||||
@ -11,9 +13,21 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
client, err := agentx.Dial("tcp", "localhost:705")
|
addr := flag.String("addr", "localhost:705", "Address to connect to (hostname:port or Unix socket path)")
|
||||||
|
flag.Parse()
|
||||||
|
|
||||||
|
var network, address string
|
||||||
|
if strings.HasPrefix(*addr, "/") {
|
||||||
|
network = "unix"
|
||||||
|
address = *addr
|
||||||
|
} else {
|
||||||
|
network = "tcp"
|
||||||
|
address = *addr
|
||||||
|
}
|
||||||
|
|
||||||
|
client, err := agentx.Dial(network, address)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Failed to dial: %v", err)
|
log.Fatalf("Failed to dial %s %s: %v", network, address, err)
|
||||||
}
|
}
|
||||||
client.Timeout = 1 * time.Minute
|
client.Timeout = 1 * time.Minute
|
||||||
client.ReconnectInterval = 1 * time.Second
|
client.ReconnectInterval = 1 * time.Second
|
||||||
|
Reference in New Issue
Block a user