Skip to content

Commit

Permalink
feat: http实例查询接口支持多个metadata条件查询
Browse files Browse the repository at this point in the history
  • Loading branch information
WTIFS committed May 20, 2024
1 parent 6c4e593 commit 1600d6b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
7 changes: 5 additions & 2 deletions apiserver/httpserver/utils/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -389,10 +389,13 @@ func ParseQueryParams(req *restful.Request) map[string]string {
queryParams := make(map[string]string)
for key, value := range req.Request.URL.Query() {
if len(value) > 0 {
queryParams[key] = value[0] // 暂时默认只支持一个查询
if key == "keys" || key == "values" {
queryParams[key] = strings.Join(value, ",")
} else {
queryParams[key] = value[0] // 暂时默认只支持一个查询
}
}
}

return queryParams
}

Expand Down
13 changes: 12 additions & 1 deletion service/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"errors"
"fmt"
"strconv"
"strings"
"time"

"github.com/gogo/protobuf/jsonpb"
Expand Down Expand Up @@ -1237,7 +1238,17 @@ func preGetInstances(query map[string]string) (map[string]string, map[string]str
apimodel.Code_InvalidQueryInsParameter, "instance metadata key and value must be both provided")
}
if metaKeyAvail {
metaFilter = map[string]string{metaKey: metaValue}
metaFilter = map[string]string{}
keys := strings.Split(metaKey, ",")
values := strings.Split(metaValue, ",")
if len(keys) == len(values) {
for i := range keys {
metaFilter[keys[i]] = values[i]
}
} else {
return nil, nil, api.NewBatchQueryResponseWithMsg(
apimodel.Code_InvalidQueryInsParameter, "instance metadata key and value length are different")
}
}

// 以healthy为准
Expand Down

0 comments on commit 1600d6b

Please sign in to comment.