MCPcopy Index your code
hub / github.com/APIParkLab/APIPark / List

Method List

module/dynamic-module/iml.go:447–523  ·  view source on GitHub ↗
(ctx context.Context, module string, keyword string, page int, pageSize int)

Source from the content-addressed store, hash-verified

445}
446
447func (i *imlDynamicModule) List(ctx context.Context, module string, keyword string, page int, pageSize int) ([]map[string]interface{}, int64, error) {
448 d, has := driver.Get(module)
449 if !has {
450 return nil, 0, fmt.Errorf("module %s not found", module)
451 }
452 list, total, err := i.dynamicModuleService.SearchByPage(ctx, keyword, map[string]interface{}{
453 "module": module,
454 }, page, pageSize, "update_at desc")
455 if err != nil {
456 return nil, 0, err
457 }
458
459 userIDs := utils.SliceToSlice(list, func(s *dynamic_module.DynamicModule) string {
460 return s.Updater
461 })
462 clusters, err := i.clusterService.List(ctx)
463 if err != nil {
464 return nil, 0, err
465 }
466
467 userMap := i.userService.GetLabels(ctx, userIDs...)
468 items := make([]map[string]interface{}, 0, len(list))
469 suffix := fmt.Sprintf("_%s", module)
470 for _, c := range clusters {
471 err = i.dynamicClient(ctx, c.Uuid, module, func(dynamicClient gateway.IDynamicClient) error {
472 versions, err := dynamicClient.Versions(ctx, map[string]string{
473 "module": module,
474 })
475 if err != nil {
476 log.Error("get versions error", err)
477 }
478 for _, l := range list {
479 status := "未发布"
480 id := strings.TrimSuffix(l.ID, suffix)
481
482 item := map[string]interface{}{
483 "id": id,
484 "title": l.Name,
485 "driver": l.Driver,
486 "description": l.Description,
487 "updater": userMap[l.Updater],
488 "update_time": l.UpdateAt.Format("2006-01-02 15:04:05"),
489 }
490
491 tmp := make(map[string]interface{})
492 err = json.Unmarshal([]byte(l.Config), &tmp)
493 if err == nil {
494 for _, column := range d.Define().Columns() {
495 if _, ok := item[column]; ok {
496 continue
497 }
498 item[column] = tmp[column]
499
500 }
501 }
502 if versions != nil {
503 if v, ok := versions[strings.ToLower(l.ID)]; ok {
504 if v == l.Version {

Callers

nothing calls this directly

Calls 8

dynamicClientMethod · 0.95
GetFunction · 0.92
SearchByPageMethod · 0.65
ListMethod · 0.65
VersionsMethod · 0.65
ColumnsMethod · 0.65
DefineMethod · 0.65
GetLabelsMethod · 0.45

Tested by

no test coverage detected