| 231 | } |
| 232 | |
| 233 | func (i *imlImportConfigController) importApis(ctx context.Context) error { |
| 234 | data, err := unmarshal[router_dto.Export]("api") |
| 235 | if err != nil { |
| 236 | return err |
| 237 | } |
| 238 | for _, d := range data { |
| 239 | var proxy *router_dto.InputProxy |
| 240 | if d.Proxy != nil { |
| 241 | proxy = &router_dto.InputProxy{ |
| 242 | Path: d.Proxy.Path, |
| 243 | Timeout: d.Proxy.Timeout, |
| 244 | Retry: d.Proxy.Retry, |
| 245 | Headers: d.Proxy.Headers, |
| 246 | Extends: d.Proxy.Extends, |
| 247 | Plugins: d.Proxy.Plugins, |
| 248 | } |
| 249 | } |
| 250 | // 判断是否存在,如果存在,则更新 |
| 251 | _, err = i.apiModule.Detail(ctx, d.Service, d.Id) |
| 252 | if err != nil { |
| 253 | if !errors.Is(err, gorm.ErrRecordNotFound) { |
| 254 | return err |
| 255 | } |
| 256 | _, err = i.apiModule.Create(ctx, d.Service, &router_dto.Create{ |
| 257 | Id: d.Id, |
| 258 | Path: d.Path, |
| 259 | Methods: d.Method, |
| 260 | Description: d.Description, |
| 261 | MatchRules: d.MatchRules, |
| 262 | Proxy: proxy, |
| 263 | }) |
| 264 | if err != nil { |
| 265 | return fmt.Errorf("create api(%s) error: %v", d.Id, err) |
| 266 | } |
| 267 | |
| 268 | continue |
| 269 | } |
| 270 | info := &router_dto.Edit{ |
| 271 | |
| 272 | Proxy: proxy, |
| 273 | //Doc: &d.Doc, |
| 274 | } |
| 275 | |
| 276 | _, err = i.apiModule.Edit(ctx, d.Service, d.Id, info) |
| 277 | if err != nil { |
| 278 | return fmt.Errorf("update api(%s) error: %v", d.Id, err) |
| 279 | } |
| 280 | |
| 281 | } |
| 282 | return nil |
| 283 | } |
| 284 | |
| 285 | func (i *imlImportConfigController) importCatalogues(ctx context.Context) error { |
| 286 | data, err := unmarshal[catalogue_dto.ExportCatalogue]("catalogue") |