-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrepository.go
58 lines (46 loc) · 1.64 KB
/
repository.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
51
52
53
54
55
56
57
58
package vmmanagerapi
import (
"encoding/json"
"fmt"
"github.com/gadost/go-vmmanager-api/types"
)
// Repositories returns repositories
func (a *Api) Repositories() (*types.Repositories, error) {
bodyResp, err := a.NewRequest(NilPayload, "/repository", requestTypeGet, DefaultService)
var r *types.Repositories
json.Unmarshal(bodyResp, &r)
return r, err
}
// Repository return repository name/id
func (a *Api) Repository(repoid int) (*types.RepositoryName, error) {
uri := fmt.Sprintf("/repository/%d", repoid)
bodyResp, err := a.NewRequest(NilPayload, uri, requestTypeGet, DefaultService)
var r *types.RepositoryName
json.Unmarshal(bodyResp, &r)
return r, err
}
// RepositoryNew add new repository
func (a *Api) RepositoryNew(params *types.RepositoryNew) (*types.Tasks, error) {
payload, _ := json.Marshal(params)
bodyResp, err := a.NewRequest(payload, "/repository", requestTypePost, DefaultService)
var r *types.Tasks
json.Unmarshal(bodyResp, &r)
return r, err
}
// RepositoryUpdate update repository params
func (a *Api) RepositoryUpdate(repoid int, params *types.RepositoryNew) (*types.Task, error) {
uri := fmt.Sprintf("/repository/%d", repoid)
payload, _ := json.Marshal(params)
bodyResp, err := a.NewRequest(payload, uri, requestTypePost, DefaultService)
var r *types.Task
json.Unmarshal(bodyResp, &r)
return r, err
}
// RepositoryDelete delete repository
func (a *Api) RepositoryDelete(repoid int) (*types.DeletedResponse, error) {
uri := fmt.Sprintf("/repository/%d", repoid)
bodyResp, err := a.NewRequest(NilPayload, uri, requestTypeDelete, DefaultService)
var r *types.DeletedResponse
json.Unmarshal(bodyResp, &r)
return r, err
}