- Notifications
You must be signed in to change notification settings - Fork 147
/
Copy pathrepo_key.go
50 lines (42 loc) · 1.51 KB
/
repo_key.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
// Copyright 2015 The Gogs Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package gogs
import (
"bytes"
"encoding/json"
"fmt"
"time"
)
typeDeployKeystruct {
IDint64`json:"id"`
Keystring`json:"key"`
URLstring`json:"url"`
Titlestring`json:"title"`
Created time.Time`json:"created_at"`
ReadOnlybool`json:"read_only"`
}
func (c*Client) ListDeployKeys(user, repostring) ([]*DeployKey, error) {
keys:=make([]*DeployKey, 0, 10)
returnkeys, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/keys", user, repo), nil, nil, &keys)
}
func (c*Client) GetDeployKey(user, repostring, keyIDint64) (*DeployKey, error) {
key:=new(DeployKey)
returnkey, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/keys/%d", user, repo, keyID), nil, nil, &key)
}
typeCreateKeyOptionstruct {
Titlestring`json:"title" binding:"Required"`
Keystring`json:"key" binding:"Required"`
}
func (c*Client) CreateDeployKey(user, repostring, optCreateKeyOption) (*DeployKey, error) {
body, err:=json.Marshal(&opt)
iferr!=nil {
returnnil, err
}
key:=new(DeployKey)
returnkey, c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/keys", user, repo), jsonHeader, bytes.NewReader(body), key)
}
func (c*Client) DeleteDeployKey(owner, repostring, keyIDint64) error {
_, err:=c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/keys/%d", owner, repo, keyID), nil, nil)
returnerr
}