forked from plouc/go-gitlab-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
namespaces.go
50 lines (38 loc) · 1.11 KB
/
namespaces.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
44
45
46
47
48
49
50
package gogitlab
import (
"encoding/json"
)
const (
namespaces_url = "/namespaces" // Get a list of namespaces associated of the authenticated user
namespaces_search_url = "/namespaces/:query" // Get all namespaces matching a string in their name/path
)
type nNamespace struct {
Id int
Path string
Kind string
FullPath string `json:"full_path,omitempty"`
}
func namespaces(u string, g *Gitlab) ([]*nNamespace, error) {
url := g.ResourceUrl(u, nil)
var namespaces []*nNamespace
contents, err := g.buildAndExecRequest("GET", url, nil)
if err == nil {
err = json.Unmarshal(contents, &namespaces)
}
return namespaces, err
}
func (g *Gitlab) Namespaces() ([]*nNamespace, error) {
return namespaces(namespaces_url, g)
}
func (g *Gitlab) SearchNamespaces(query string) ([]*nNamespace, error) {
url, opaque := g.ResourceUrlRaw(
namespaces_search_url,
map[string]string{":query": query},
)
var namespaces []*nNamespace
contents, err := g.buildAndExecRequestRaw("GET", url, opaque, nil)
if err == nil {
err = json.Unmarshal(contents, &namespaces)
}
return namespaces, err
}