forked from Virtomize/confluence-go-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
search.go
43 lines (38 loc) · 1 KB
/
search.go
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
40
41
42
43
package goconfluence
import (
"net/url"
"strconv"
)
// getContentEndpoint creates the correct api endpoint by given id
func (a *API) getSearchEndpoint() (*url.URL, error) {
return url.ParseRequestURI(a.endPoint.String() + "/search")
}
// Search querys confluence using CQL
func (a *API) Search(query SearchQuery) (*Search, error) {
ep, err := a.getSearchEndpoint()
if err != nil {
return nil, err
}
ep.RawQuery = addSearchQueryParams(query).Encode()
return a.SendSearchRequest(ep, "GET")
}
// addSearchQueryParams adds the defined query parameters
func addSearchQueryParams(query SearchQuery) *url.Values {
data := url.Values{}
if query.CQL != "" {
data.Set("cql", query.CQL)
}
if query.CQLContext != "" {
data.Set("cqlcontext", query.CQLContext)
}
if query.IncludeArchivedSpaces == true {
data.Set("includeArchivedSpaces", "true")
}
if query.Limit != 0 {
data.Set("limit", strconv.Itoa(query.Limit))
}
if query.Start != 0 {
data.Set("start", strconv.Itoa(query.Start))
}
return &data
}