(cli *SeesawCLI, args []string)
| 225 | } |
| 226 | |
| 227 | func showBackend(cli *SeesawCLI, args []string) error { |
| 228 | if len(args) > 1 { |
| 229 | fmt.Println("show backend <backend>") |
| 230 | return nil |
| 231 | } |
| 232 | |
| 233 | vservers, err := cli.seesaw.Vservers() |
| 234 | if err != nil { |
| 235 | return fmt.Errorf("Failed to get vservers: %v", err) |
| 236 | } |
| 237 | |
| 238 | // If no args given, list all backends. |
| 239 | showAll := len(args) == 0 |
| 240 | |
| 241 | backendsMap := make(map[string]seesaw.Destinations) |
| 242 | for _, v := range vservers { |
| 243 | for _, s := range v.Services { |
| 244 | for _, d := range s.Destinations { |
| 245 | if showAll || strings.HasPrefix(d.Backend.Hostname, args[0]) { |
| 246 | list, ok := backendsMap[d.Backend.Hostname] |
| 247 | if !ok { |
| 248 | list = make([]*seesaw.Destination, 0) |
| 249 | } |
| 250 | list = append(list, d) |
| 251 | backendsMap[d.Backend.Hostname] = list |
| 252 | } |
| 253 | } |
| 254 | } |
| 255 | } |
| 256 | |
| 257 | if len(backendsMap) == 0 { |
| 258 | if len(args) > 0 { |
| 259 | return fmt.Errorf("backend '%v...' not found", args[0]) |
| 260 | } |
| 261 | return fmt.Errorf("no backends found") |
| 262 | } |
| 263 | |
| 264 | backends := make([]string, 0) |
| 265 | for backend := range backendsMap { |
| 266 | backends = append(backends, backend) |
| 267 | } |
| 268 | |
| 269 | if len(backends) == 1 { |
| 270 | // Exactly 1 backend found, print details. |
| 271 | printHdr("Backend") |
| 272 | fmt.Printf(" Hostname: %v\n", backends[0]) |
| 273 | fmt.Printf(" Destinations:\n") |
| 274 | dests := backendsMap[backends[0]] |
| 275 | sort.Sort(dests) |
| 276 | for i, d := range dests { |
| 277 | fmt.Printf(" [%3d] %v\n", i+1, destSummary(d, vservers)) |
| 278 | } |
| 279 | return nil |
| 280 | } |
| 281 | |
| 282 | // Multiple matching backends, just list their names. |
| 283 | sort.Strings(backends) |
| 284 | printHdr("Backends") |
nothing calls this directly
no test coverage detected