(cli *SeesawCLI, args []string)
| 315 | } |
| 316 | |
| 317 | func showDestination(cli *SeesawCLI, args []string) error { |
| 318 | if len(args) > 1 { |
| 319 | fmt.Println("show destinations <vserver|destination>") |
| 320 | return nil |
| 321 | } |
| 322 | |
| 323 | vservers, err := cli.seesaw.Vservers() |
| 324 | if err != nil { |
| 325 | return fmt.Errorf("Failed to get vservers: %v", err) |
| 326 | } |
| 327 | |
| 328 | // If no args given, list all destinations. |
| 329 | showAll := len(args) == 0 |
| 330 | |
| 331 | var dests seesaw.Destinations = make([]*seesaw.Destination, 0) |
| 332 | for _, v := range vservers { |
| 333 | for _, s := range v.Services { |
| 334 | for _, d := range s.Destinations { |
| 335 | if showAll || strings.HasPrefix(d.Name, args[0]) { |
| 336 | dests = append(dests, d) |
| 337 | } |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | |
| 342 | switch len(dests) { |
| 343 | case 0: |
| 344 | if len(args) > 0 { |
| 345 | return fmt.Errorf("destination '%v...' not found", args[0]) |
| 346 | } |
| 347 | return fmt.Errorf("no destinations found") |
| 348 | case 1: |
| 349 | // Exactly one destination found, print destination details. |
| 350 | d := dests[0] |
| 351 | vserverName := d.VserverName |
| 352 | if v, ok := vservers[d.VserverName]; ok && !v.Enabled { |
| 353 | vserverName = vserverName + " (disabled)" |
| 354 | } |
| 355 | printHdr("Destination") |
| 356 | printVal("Name:", d.Name) |
| 357 | printVal("Vserver:", vserverName) |
| 358 | printVal("Backend:", d.Backend.Hostname) |
| 359 | printVal("Enabled:", d.Enabled) |
| 360 | printVal("Healthy:", d.Healthy) |
| 361 | printVal("Active:", d.Active) |
| 362 | // TODO(angusc): Show healthcheck history and status details. |
| 363 | return nil |
| 364 | } |
| 365 | |
| 366 | // Multiple matching destinations, just print a summary. |
| 367 | printHdr("Destinations") |
| 368 | sort.Sort(dests) |
| 369 | for i, d := range dests { |
| 370 | fmt.Printf("[%4d] %v\n", i+1, destSummary(d, vservers)) |
| 371 | } |
| 372 | return nil |
| 373 | } |
| 374 |
nothing calls this directly
no test coverage detected