github.com/IBM-Cloud/bluemix-go@v0.0.0-20240314082800-4e02a69b84b2/api/globalsearch/globalsearchv2/search.go (about)

     1  package globalsearchv2
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/IBM-Cloud/bluemix-go/client"
     7  )
     8  
     9  type SearchResult struct {
    10  	Items       []Item `json:"items"`
    11  	MoreData    bool   `json:"more_data"`
    12  	Token       string `json:"token"`
    13  	FilterError bool   `json:"filter_error"`
    14  	PartialData int    `json:"partial_data"`
    15  }
    16  
    17  type Item struct {
    18  	Name        string   `json:"name,omitempty"`
    19  	CRN         string   `json:"crn,omitempty"`
    20  	ServiceName string   `json:"service_name,omitempty"`
    21  	Region      string   `json:"region,omitempty"`
    22  	Family      string   `json:"family,omitempty"`
    23  	Type        string   `json:"type,omitempty"`
    24  	ResourceId  string   `json:"resource_id,omitempty"`
    25  	Tags        []string `json:"tags,omitempty"`
    26  }
    27  
    28  type SearchBody struct {
    29  	Query  string   `json:"query"`
    30  	Fields []string `json:"fields,omitempty"`
    31  	Token  string   `json:"token,omitempty"`
    32  }
    33  
    34  type Searches interface {
    35  	PostQuery(searchBody SearchBody) (SearchResult, error)
    36  }
    37  
    38  type searches struct {
    39  	client *client.Client
    40  }
    41  
    42  func newSearchAPI(c *client.Client) Searches {
    43  	return &searches{
    44  		client: c,
    45  	}
    46  }
    47  
    48  func (r *searches) PostQuery(searchBody SearchBody) (SearchResult, error) {
    49  	searchResult := SearchResult{}
    50  	rawURL := fmt.Sprintf("/v2/resources/search")
    51  	_, err := r.client.Post(rawURL, &searchBody, &searchResult)
    52  	if err != nil {
    53  		return searchResult, err
    54  	}
    55  	return searchResult, nil
    56  }