#35 improve code structure

This commit is contained in:
Unknwon 2016-08-03 11:50:33 -07:00
parent e3ad13b2f3
commit d725743594
2 changed files with 13 additions and 8 deletions

View File

@ -14,7 +14,7 @@ import (
)
func Version() string {
return "0.10.0"
return "0.10.1"
}
// Client represents a Gogs API client.

View File

@ -16,11 +16,6 @@ type Label struct {
Color string `json:"color"`
}
type LabelOption struct {
Name string `json:"name"`
Color string `json:"color"`
}
func (c *Client) ListRepoLabels(owner, repo string) ([]*Label, error) {
labels := make([]*Label, 0, 10)
return labels, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/labels", owner, repo), nil, nil, &labels)
@ -31,7 +26,12 @@ func (c *Client) GetRepoLabel(owner, repo string, id int64) (*Label, error) {
return label, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/labels/%d", owner, repo, id), nil, nil, label)
}
func (c *Client) CreateLabel(owner, repo string, opt LabelOption) (*Label, error) {
type CreateLabelOption struct {
Name string `json:"name" binding:"Required"`
Color string `json:"color" binding:"Required;Size(7)"`
}
func (c *Client) CreateLabel(owner, repo string, opt CreateLabelOption) (*Label, error) {
body, err := json.Marshal(&opt)
if err != nil {
return nil, err
@ -41,7 +41,12 @@ func (c *Client) CreateLabel(owner, repo string, opt LabelOption) (*Label, error
jsonHeader, bytes.NewReader(body), label)
}
func (c *Client) EditLabel(owner, repo string, id int64, opt LabelOption) (*Label, error) {
type EditLabelOption struct {
Name *string `json:"name"`
Color *string `json:"color"`
}
func (c *Client) EditLabel(owner, repo string, id int64, opt EditLabelOption) (*Label, error) {
body, err := json.Marshal(&opt)
if err != nil {
return nil, err