()
| 232 | } |
| 233 | |
| 234 | func (i *imlInitController) OnInit() { |
| 235 | register.Handle(func(v server.Server) { |
| 236 | ctx := utils.SetUserId(context.Background(), "admin") |
| 237 | |
| 238 | err := i.transaction.Transaction(ctx, func(ctx context.Context) error { |
| 239 | teams, err := i.teamModule.Search(ctx, "") |
| 240 | if err != nil { |
| 241 | return fmt.Errorf("get teams error: %v", err) |
| 242 | } |
| 243 | if len(teams) > 0 { |
| 244 | return nil |
| 245 | } |
| 246 | items, err := i.catalogueModule.Search(ctx, "") |
| 247 | if err != nil { |
| 248 | return fmt.Errorf("get catalogue error: %v", err) |
| 249 | } |
| 250 | catalogueId := uuid.New().String() |
| 251 | if len(items) == 0 { |
| 252 | err = i.catalogueModule.Create(ctx, &catalogue_dto.CreateCatalogue{ |
| 253 | Id: catalogueId, |
| 254 | Name: "Default Category", |
| 255 | }) |
| 256 | if err != nil { |
| 257 | return fmt.Errorf("create default catalogue error: %v", err) |
| 258 | } |
| 259 | } else { |
| 260 | catalogueId = items[0].Id |
| 261 | } |
| 262 | |
| 263 | info, err := i.teamModule.Create(ctx, &team_dto.CreateTeam{ |
| 264 | Name: "Default Team", |
| 265 | Description: "Auto created By APIPark", |
| 266 | }) |
| 267 | if err != nil { |
| 268 | return fmt.Errorf("create default team error: %v", err) |
| 269 | } |
| 270 | app, err := i.appModule.CreateApp(ctx, info.Id, &service_dto.CreateApp{ |
| 271 | Name: "Demo Application", |
| 272 | Description: "Auto created By APIPark", |
| 273 | }) |
| 274 | if err != nil { |
| 275 | return fmt.Errorf("create default app error: %v", err) |
| 276 | } |
| 277 | // 创建Rest服务 |
| 278 | restPath := "/rest-demo" |
| 279 | serviceInfo, err := i.serviceModule.Create(ctx, info.Id, &service_dto.CreateService{ |
| 280 | Name: "REST Demo Service", |
| 281 | Prefix: "/rest-demo", |
| 282 | Description: "Auto created By APIPark", |
| 283 | ServiceType: "public", |
| 284 | Catalogue: catalogueId, |
| 285 | ApprovalType: "auto", |
| 286 | Kind: "rest", |
| 287 | }) |
| 288 | if err != nil { |
| 289 | return fmt.Errorf("create default service error: %v", err) |
| 290 | } |
| 291 | path := fmt.Sprintf("/%s/", strings.Trim(restPath, "/")) |
nothing calls this directly
no test coverage detected