From adb2874e6001c41c2f8d0f127598673ab09e906d Mon Sep 17 00:00:00 2001 From: cuigh Date: Mon, 16 Apr 2018 17:44:44 +0800 Subject: [PATCH] Fuzzy matching when filtering services --- biz/docker/service.go | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/biz/docker/service.go b/biz/docker/service.go index dabcd1a..a7b174c 100644 --- a/biz/docker/service.go +++ b/biz/docker/service.go @@ -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 })