| 300 | } |
| 301 | |
| 302 | func (i *imlRouterModule) Edit(ctx context.Context, serviceId string, apiId string, dto *router_dto.Edit) (*router_dto.SimpleDetail, error) { |
| 303 | _, err := i.serviceService.Check(ctx, serviceId, asServer) |
| 304 | if err != nil { |
| 305 | return nil, err |
| 306 | } |
| 307 | |
| 308 | err = i.transaction.Transaction(ctx, func(ctx context.Context) error { |
| 309 | if dto.Path != nil { |
| 310 | err = i.apiService.Exist(ctx, apiId, &api.Exist{Path: *dto.Path, Methods: *dto.Methods}) |
| 311 | if err != nil { |
| 312 | return err |
| 313 | } |
| 314 | } |
| 315 | if dto.Proxy != nil { |
| 316 | err = i.apiService.SaveProxy(ctx, apiId, router_dto.ToServiceProxy(dto.Proxy)) |
| 317 | if err != nil { |
| 318 | return err |
| 319 | } |
| 320 | } |
| 321 | var match *string |
| 322 | if dto.MatchRules != nil { |
| 323 | ml, _ := json.Marshal(dto.MatchRules) |
| 324 | m := string(ml) |
| 325 | match = &m |
| 326 | } |
| 327 | err = i.apiService.Save(ctx, apiId, &api.Edit{ |
| 328 | Name: dto.Name, |
| 329 | Description: dto.Description, |
| 330 | Methods: dto.Methods, |
| 331 | Protocols: dto.Protocols, |
| 332 | Disable: dto.Disable, |
| 333 | Path: dto.Path, |
| 334 | Upstream: dto.Upstream, |
| 335 | Match: match, |
| 336 | }) |
| 337 | if err != nil { |
| 338 | return err |
| 339 | } |
| 340 | |
| 341 | return nil |
| 342 | |
| 343 | }) |
| 344 | if err != nil { |
| 345 | return nil, err |
| 346 | } |
| 347 | return i.SimpleDetail(ctx, serviceId, apiId) |
| 348 | } |
| 349 | |
| 350 | func (i *imlRouterModule) Delete(ctx context.Context, serviceId string, apiId string) error { |
| 351 | _, err := i.serviceService.Check(ctx, serviceId, asServer) |