mirror of
https://github.com/pcvolkmer/docker-pps.git
synced 2025-04-19 09:46:50 +00:00
Extract client host option setting
This commit is contained in:
parent
a4b9fd69c9
commit
f831c02e12
38
main.go
38
main.go
@ -52,23 +52,7 @@ func main() {
|
||||
return
|
||||
}
|
||||
|
||||
var opts []client.Opt
|
||||
if *h != "" {
|
||||
if !strings.Contains(*h, "//") {
|
||||
*h = "tcp://" + *h
|
||||
}
|
||||
if u, err := client.ParseHostURL(*h); err == nil {
|
||||
if u.Port() != "" {
|
||||
opts = append(opts, client.WithHost(*h))
|
||||
} else {
|
||||
opts = append(opts, client.WithHost(*h+":2375"))
|
||||
}
|
||||
} else {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
dc, err := client.NewClientWithOpts(opts...)
|
||||
dc, err := client.NewClientWithOpts(getClientOpts(h)...)
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
return
|
||||
@ -157,3 +141,23 @@ func contains(uids []string, uid string) bool {
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// Get client opts from host param
|
||||
func getClientOpts(h *string) []client.Opt {
|
||||
var opts []client.Opt
|
||||
if *h != "" {
|
||||
if !strings.Contains(*h, "//") {
|
||||
*h = "tcp://" + *h
|
||||
}
|
||||
if u, err := client.ParseHostURL(*h); err == nil {
|
||||
if u.Port() != "" {
|
||||
opts = append(opts, client.WithHost(*h))
|
||||
} else {
|
||||
opts = append(opts, client.WithHost(*h+":2375"))
|
||||
}
|
||||
} else {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
return opts
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user