parent
717e04de1e
commit
8068507b50
2 changed files with 13 additions and 1 deletions
7
gogs.go
7
gogs.go
|
@ -14,7 +14,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func Version() string {
|
func Version() string {
|
||||||
return "0.0.2"
|
return "0.0.4"
|
||||||
}
|
}
|
||||||
|
|
||||||
// Client represents a Gogs API client.
|
// Client represents a Gogs API client.
|
||||||
|
@ -33,6 +33,11 @@ func NewClient(url, token string) *Client {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetHTTPClient replaces default http.Client with user given one.
|
||||||
|
func (c *Client) SetHTTPClient(client *http.Client) {
|
||||||
|
c.client = client
|
||||||
|
}
|
||||||
|
|
||||||
func (c *Client) getResponse(method, path string, header http.Header, body io.Reader) ([]byte, error) {
|
func (c *Client) getResponse(method, path string, header http.Header, body io.Reader) ([]byte, error) {
|
||||||
req, err := http.NewRequest(method, c.url+"/api/v1"+path, body)
|
req, err := http.NewRequest(method, c.url+"/api/v1"+path, body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
7
repo.go
7
repo.go
|
@ -70,6 +70,13 @@ func (c *Client) CreateOrgRepo(org string, opt CreateRepoOption) (*Repository, e
|
||||||
http.Header{"content-type": []string{"application/json"}}, bytes.NewReader(body), repo)
|
http.Header{"content-type": []string{"application/json"}}, bytes.NewReader(body), repo)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetRepo returns information of a repository of given owner.
|
||||||
|
func (c *Client) GetRepo(owner, reponame string) (*Repository, error) {
|
||||||
|
repo := new(Repository)
|
||||||
|
return repo, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s", owner, reponame),
|
||||||
|
http.Header{"content-type": []string{"application/json"}}, nil, repo)
|
||||||
|
}
|
||||||
|
|
||||||
// DeleteRepo deletes a repository of user or organization.
|
// DeleteRepo deletes a repository of user or organization.
|
||||||
func (c *Client) DeleteRepo(owner, repo string) error {
|
func (c *Client) DeleteRepo(owner, repo string) error {
|
||||||
_, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s", owner, repo), nil, nil)
|
_, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s", owner, repo), nil, nil)
|
||||||
|
|
Loading…
Reference in a new issue