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

Method Search

module/router/iml.go:177–223  ·  view source on GitHub ↗
(ctx context.Context, keyword string, serviceId string)

Source from the content-addressed store, hash-verified

175}
176
177func (i *imlRouterModule) Search(ctx context.Context, keyword string, serviceId string) ([]*router_dto.Item, error) {
178 _, err := i.serviceService.Check(ctx, serviceId, asServer)
179 if err != nil {
180 return nil, err
181 }
182
183 list, err := i.apiService.Search(ctx, keyword, map[string]interface{}{
184 "service": serviceId,
185 })
186 if err != nil {
187 return nil, err
188 }
189 if len(list) == 0 {
190 return []*router_dto.Item{}, nil
191 }
192 apiInfos, err := i.apiService.ListInfo(ctx, utils.SliceToSlice(list, func(s *api.API) string {
193 return s.UUID
194 })...)
195 if err != nil {
196 return nil, err
197 }
198 utils.Sort(apiInfos, func(a, b *api.Info) bool {
199 return a.UpdateAt.After(b.UpdateAt)
200 })
201 out := utils.SliceToSlice(apiInfos, func(item *api.Info) *router_dto.Item {
202 protocols := []string{"HTTP", "HTTPS"}
203 if len(item.Protocols) > 0 {
204 protocols = item.Protocols
205 }
206 return &router_dto.Item{
207 Id: item.UUID,
208 Name: item.Name,
209 Methods: item.Methods,
210 Protocols: protocols,
211 Path: item.Path,
212 Description: item.Description,
213 Disable: item.Disable,
214 Creator: auto.UUID(item.Creator),
215 Updater: auto.UUID(item.Updater),
216 CreateTime: auto.TimeLabel(item.CreateAt),
217 UpdateTime: auto.TimeLabel(item.UpdateAt),
218 CanDelete: true,
219 }
220 })
221
222 return out, nil
223}
224
225func (i *imlRouterModule) SimpleSearch(ctx context.Context, keyword string, serviceId string) ([]*router_dto.SimpleItem, error) {
226 _, err := i.serviceService.Check(ctx, serviceId, asServer)

Callers

nothing calls this directly

Calls 4

CheckMethod · 0.65
SearchMethod · 0.65
ListInfoMethod · 0.65
SortMethod · 0.65

Tested by

no test coverage detected