summaryrefslogtreecommitdiff
path: root/pkg/bindings/search.go
blob: 0f462357cea96d7fc122a1a21f9612b5926dce68 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package bindings

import (
	"net/http"
	"strconv"

	"github.com/containers/libpod/libpod/image"
)

type ImageSearchFilters struct {
	Automated bool `json:"automated"`
	Official  bool `json:"official"`
	Stars     int  `json:"stars"`
}

// TODO This method can be concluded when we determine how we want the filters to work on the
// API end
func (i *ImageSearchFilters) ToMapJSON() string {
	return ""
}

func (c Connection) SearchImages(term string, limit int, filters *ImageSearchFilters) ([]image.SearchResult, error) {
	var (
		searchResults []image.SearchResult
	)
	params := make(map[string]string)
	params["term"] = term
	if limit > 0 {
		params["limit"] = strconv.Itoa(limit)
	}
	if filters != nil {
		params["filters"] = filters.ToMapJSON()
	}
	response, err := c.newRequest(http.MethodGet, "/images/search", nil, params)
	if err != nil {
		return searchResults, nil
	}
	return searchResults, response.Process(&searchResults)
}