forked from cvbarros/go-teamcity
/
locator.go
39 lines (31 loc) · 1.09 KB
/
locator.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
package teamcity
import (
"fmt"
"net/url"
)
//Locator represents a arbitraty locator to be used when querying resources, such as id:, type:, or key:
//These are used in GET requests within the URL so must be properly escaped
type Locator string
//LocatorID creates a locator for a Project/BuildType by Id
func LocatorID(id string) Locator {
return Locator(url.QueryEscape("id:") + id)
}
//LocatorIDInt creates a locator for a Project/BuildType by Id where the Id's an integer
func LocatorIDInt(id int) Locator {
return Locator(url.QueryEscape("id:") + fmt.Sprintf("%d", id))
}
//LocatorName creates a locator for Project/BuildType by Name
func LocatorName(name string) Locator {
return Locator(url.QueryEscape("name:") + url.PathEscape(name))
}
//LocatorKey creates a locator for Group by Key
func LocatorKey(key string) Locator {
return Locator(url.QueryEscape("key:") + url.PathEscape(key))
}
//LocatorType creates a locator for a Project Feature by Type
func LocatorType(id string) Locator {
return Locator(url.QueryEscape("type:") + id)
}
func (l Locator) String() string {
return string(l)
}