| 423 | } |
| 424 | |
| 425 | func (m *imlServiceDiff) Out(ctx context.Context, diff *service_diff.Diff) (*DiffOut, error) { |
| 426 | |
| 427 | clusters, err := m.clusterService.List(ctx, diff.Clusters...) |
| 428 | if err != nil { |
| 429 | return nil, err |
| 430 | } |
| 431 | if len(clusters) == 0 { |
| 432 | return nil, fmt.Errorf("unset gateway for clusters %v", diff.Clusters) |
| 433 | } |
| 434 | |
| 435 | out := &DiffOut{} |
| 436 | out.Routers = utils.SliceToSlice(diff.Apis, func(i *service_diff.ApiDiff) *RouterDiffOut { |
| 437 | return &RouterDiffOut{ |
| 438 | Name: i.Name, |
| 439 | Methods: i.Method, |
| 440 | Path: i.Path, |
| 441 | Change: i.Change, |
| 442 | Status: i.Status, |
| 443 | Protocols: i.Protocol, |
| 444 | Disable: i.Disable, |
| 445 | } |
| 446 | }) |
| 447 | |
| 448 | for _, u := range diff.Upstreams { |
| 449 | if u.Data == nil { |
| 450 | continue |
| 451 | } |
| 452 | typeValue := u.Data.Type |
| 453 | |
| 454 | if typeValue == "" { |
| 455 | typeValue = "static" |
| 456 | } |
| 457 | out.Upstreams = append(out.Upstreams, &UpstreamDiffOut{ |
| 458 | Change: u.Change, |
| 459 | Type: typeValue, |
| 460 | Status: u.Status, |
| 461 | Addr: utils.SliceToSlice(u.Data.Nodes, func(i *upstream.NodeConfig) string { |
| 462 | return i.Address |
| 463 | }), |
| 464 | }) |
| 465 | } |
| 466 | out.Strategies = utils.SliceToSlice(diff.Strategies, func(i *service_diff.StrategyDiff) *StrategyDiffOut { |
| 467 | return &StrategyDiffOut{ |
| 468 | Name: i.Name, |
| 469 | Priority: i.Priority, |
| 470 | Change: i.Change, |
| 471 | Status: i.Status, |
| 472 | } |
| 473 | }) |
| 474 | return out, nil |
| 475 | } |