mirror of
https://github.com/cuigh/swirl
synced 2025-01-01 00:32:09 +00:00
Fuzzy matching when filtering services
This commit is contained in:
parent
f2a4b7209c
commit
adb2874e60
@ -32,15 +32,21 @@ func ServiceList(name string, pageIndex, pageSize int) (infos []*model.ServiceLi
|
|||||||
)
|
)
|
||||||
|
|
||||||
// acquire services
|
// acquire services
|
||||||
opts := types.ServiceListOptions{}
|
services, err = cli.ServiceList(ctx, types.ServiceListOptions{})
|
||||||
if name != "" {
|
|
||||||
opts.Filters = filters.NewArgs()
|
|
||||||
opts.Filters.Add("name", name)
|
|
||||||
}
|
|
||||||
services, err = cli.ServiceList(ctx, opts)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if name != "" {
|
||||||
|
j := 0
|
||||||
|
name = strings.ToLower(name)
|
||||||
|
for i, l := 0, len(services); i < l; i++ {
|
||||||
|
if strings.Contains(strings.ToLower(services[i].Spec.Name), name) {
|
||||||
|
services[j] = services[i]
|
||||||
|
j++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
services = services[:j]
|
||||||
|
}
|
||||||
sort.Slice(services, func(i, j int) bool {
|
sort.Slice(services, func(i, j int) bool {
|
||||||
return services[i].Spec.Name < services[j].Spec.Name
|
return services[i].Spec.Name < services[j].Spec.Name
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user