-
Notifications
You must be signed in to change notification settings - Fork 3
/
namespace.go
39 lines (33 loc) · 912 Bytes
/
namespace.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 client
import (
"encoding/json"
"golang.org/x/net/context"
"net/url"
)
func (api *APIClient) GetNamespace(ctx context.Context) (namespace string, err error) {
resp, err := api.cli.Get(ctx, "/namespace", nil, nil)
if err == nil {
var nsJson map[string]string
err = json.NewDecoder(resp.Body).Decode(&nsJson)
resp.EnsureClosed()
namespace = nsJson["Namespace"]
}
return namespace, err
}
func (api *APIClient) SetNamespace(ctx context.Context, namespace string) error {
query := url.Values{}
query.Set("namespace", namespace)
resp, err := api.cli.Post(ctx, "/namespace", query, nil, nil)
resp.EnsureClosed()
return err
}
func (api *APIClient) RemoveNamespace(ctx context.Context, force bool) error {
var query url.Values
if force {
query = url.Values{}
query.Set("force", "1")
}
resp, err := api.cli.Delete(ctx, "/namespace", query, nil)
resp.EnsureClosed()
return err
}