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

Method Services

module/catalogue/iml.go:437–512  ·  view source on GitHub ↗
(ctx context.Context, keyword string)

Source from the content-addressed store, hash-verified

435}
436
437func (i *imlCatalogueModule) Services(ctx context.Context, keyword string) ([]*catalogue_dto.ServiceItem, error) {
438
439 serviceTags, err := i.serviceTagService.List(ctx, nil, nil)
440 if err != nil {
441 return nil, err
442 }
443 serviceTagMap := utils.SliceToMapArrayO(serviceTags, func(t *service_tag.Tag) (string, string) {
444 return t.Sid, t.Tid
445 })
446
447 items, err := i.serviceService.SearchPublicServices(ctx, keyword)
448 if err != nil {
449 return nil, err
450 }
451 serviceIds := utils.SliceToSlice(items, func(i *service.Service) string {
452 return i.Id
453 })
454 overviewMap, err := i.serviceOverviewService.Map(ctx, serviceIds...)
455 if err != nil {
456 return nil, err
457 }
458 serviceIds = utils.SliceToSlice(serviceIds, func(s string) string {
459 return s
460 }, func(s string) bool {
461 // 只展示已发布的服务
462 if info, ok := overviewMap[s]; ok && info.IsReleased {
463 return true
464 }
465 return false
466 })
467 if len(serviceIds) < 1 {
468 return nil, nil
469 }
470
471 subscriberCountMap, err := i.subscribeService.CountMapByService(ctx, subscribe.ApplyStatusSubscribe, serviceIds...)
472 if err != nil {
473 return nil, err
474 }
475 invokeStatisticMap, err := i.ProviderStatistics(ctx, time.Now().Add(-24*30*time.Hour), time.Now(), serviceIds...)
476 if err != nil {
477 return nil, err
478 }
479
480 result := make([]*catalogue_dto.ServiceItem, 0, len(items))
481 for _, v := range items {
482
483 ov, ok := overviewMap[v.Id]
484 if !ok || ov.ReleaseApiCount < 1 {
485 continue
486 }
487
488 result = append(result, &catalogue_dto.ServiceItem{
489 Id: v.Id,
490 Name: v.Name,
491 Tags: auto.List(serviceTagMap[v.Id]),
492 Catalogue: auto.UUID(v.Catalogue),
493 SubscriberNum: subscriberCountMap[v.Id],
494 ApiNum: ov.ReleaseApiCount,

Callers

nothing calls this directly

Calls 6

ProviderStatisticsMethod · 0.95
ListMethod · 0.65
SearchPublicServicesMethod · 0.65
MapMethod · 0.65
CountMapByServiceMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected