mirror of
https://github.com/cuigh/swirl
synced 2024-12-28 23:02:02 +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
|
||||
opts := types.ServiceListOptions{}
|
||||
if name != "" {
|
||||
opts.Filters = filters.NewArgs()
|
||||
opts.Filters.Add("name", name)
|
||||
}
|
||||
services, err = cli.ServiceList(ctx, opts)
|
||||
services, err = cli.ServiceList(ctx, types.ServiceListOptions{})
|
||||
if err != nil {
|
||||
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 {
|
||||
return services[i].Spec.Name < services[j].Spec.Name
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user