Commit 42a7783d authored by Daniel Martí's avatar Daniel Martí Committed by Sander van Harmelen

Warning fixes and other cleanups (#62)

* Simplify some code via gosimple

See https://github.com/dominikh/go-simple.

* strings: use bytes.Buffer directly

It has methods to write strings and bytes already, which is much easier
and also faster than going through a regular write of []byte.

* Run go fmt

* CI: Bump Go versions
parent 4f1f8d2b
language: go language: go
go: go:
- 1.4.3 - 1.5.4
- 1.5.1 - 1.6.3
...@@ -201,10 +201,5 @@ func (s *BranchesService) DeleteBranch(pid interface{}, branch string) (*Respons ...@@ -201,10 +201,5 @@ func (s *BranchesService) DeleteBranch(pid interface{}, branch string) (*Respons
return nil, err return nil, err
} }
resp, err := s.client.Do(req, nil) return s.client.Do(req, nil)
if err != nil {
return resp, err
}
return resp, err
} }
...@@ -148,10 +148,5 @@ func (s *DeployKeysService) DeleteDeployKey(pid interface{}, deployKey int) (*Re ...@@ -148,10 +148,5 @@ func (s *DeployKeysService) DeleteDeployKey(pid interface{}, deployKey int) (*Re
return nil, err return nil, err
} }
resp, err := s.client.Do(req, nil) return s.client.Do(req, nil)
if err != nil {
return resp, err
}
return resp, err
} }
...@@ -210,11 +210,7 @@ func (c *Client) SetBaseURL(urlStr string) error { ...@@ -210,11 +210,7 @@ func (c *Client) SetBaseURL(urlStr string) error {
var err error var err error
c.baseURL, err = url.Parse(urlStr) c.baseURL, err = url.Parse(urlStr)
if err != nil {
return err return err
}
return nil
} }
// NewRequest creates an API request. A relative URL path can be provided in // NewRequest creates an API request. A relative URL path can be provided in
......
...@@ -161,12 +161,7 @@ func (s *GroupsService) DeleteGroup(gid interface{}) (*Response, error) { ...@@ -161,12 +161,7 @@ func (s *GroupsService) DeleteGroup(gid interface{}) (*Response, error) {
return nil, err return nil, err
} }
resp, err := s.client.Do(req, nil) return s.client.Do(req, nil)
if err != nil {
return resp, err
}
return resp, err
} }
// SearchGroup get all groups that match your string in their name or path. // SearchGroup get all groups that match your string in their name or path.
...@@ -319,10 +314,5 @@ func (s *GroupsService) RemoveGroupMember(gid interface{}, user int) (*Response, ...@@ -319,10 +314,5 @@ func (s *GroupsService) RemoveGroupMember(gid interface{}, user int) (*Response,
return nil, err return nil, err
} }
resp, err := s.client.Do(req, nil) return s.client.Do(req, nil)
if err != nil {
return resp, err
}
return resp, err
} }
...@@ -273,10 +273,5 @@ func (s *IssuesService) DeleteIssue(pid interface{}, issue int) (*Response, erro ...@@ -273,10 +273,5 @@ func (s *IssuesService) DeleteIssue(pid interface{}, issue int) (*Response, erro
return nil, err return nil, err
} }
resp, err := s.client.Do(req, nil) return s.client.Do(req, nil)
if err != nil {
return resp, err
}
return resp, err
} }
...@@ -127,12 +127,7 @@ func (s *LabelsService) DeleteLabel(pid interface{}, opt *DeleteLabelOptions) (* ...@@ -127,12 +127,7 @@ func (s *LabelsService) DeleteLabel(pid interface{}, opt *DeleteLabelOptions) (*
return nil, err return nil, err
} }
resp, err := s.client.Do(req, nil) return s.client.Do(req, nil)
if err != nil {
return resp, err
}
return resp, err
} }
// UpdateLabelOptions represents the available UpdateLabel() options. // UpdateLabelOptions represents the available UpdateLabel() options.
......
...@@ -212,12 +212,7 @@ func (s *ProjectSnippetsService) DeleteSnippet(pid interface{}, snippet int) (*R ...@@ -212,12 +212,7 @@ func (s *ProjectSnippetsService) DeleteSnippet(pid interface{}, snippet int) (*R
return nil, err return nil, err
} }
resp, err := s.client.Do(req, nil) return s.client.Do(req, nil)
if err != nil {
return resp, err
}
return resp, err
} }
// SnippetContent returns the raw project snippet as plain text. // SnippetContent returns the raw project snippet as plain text.
......
...@@ -488,12 +488,7 @@ func (s *ProjectsService) DeleteProject(pid interface{}) (*Response, error) { ...@@ -488,12 +488,7 @@ func (s *ProjectsService) DeleteProject(pid interface{}) (*Response, error) {
return nil, err return nil, err
} }
resp, err := s.client.Do(req, nil) return s.client.Do(req, nil)
if err != nil {
return resp, err
}
return resp, err
} }
// ProjectMember represents a project member. // ProjectMember represents a project member.
...@@ -665,12 +660,7 @@ func (s *ProjectsService) DeleteProjectMember(pid interface{}, user int) (*Respo ...@@ -665,12 +660,7 @@ func (s *ProjectsService) DeleteProjectMember(pid interface{}, user int) (*Respo
return nil, err return nil, err
} }
resp, err := s.client.Do(req, nil) return s.client.Do(req, nil)
if err != nil {
return resp, err
}
return resp, err
} }
// ProjectHook represents a project hook. // ProjectHook represents a project hook.
...@@ -844,12 +834,7 @@ func (s *ProjectsService) DeleteProjectHook(pid interface{}, hook int) (*Respons ...@@ -844,12 +834,7 @@ func (s *ProjectsService) DeleteProjectHook(pid interface{}, hook int) (*Respons
return nil, err return nil, err
} }
resp, err := s.client.Do(req, nil) return s.client.Do(req, nil)
if err != nil {
return resp, err
}
return resp, err
} }
// ProjectForkRelation represents a project fork relationship. // ProjectForkRelation represents a project fork relationship.
...@@ -900,12 +885,7 @@ func (s *ProjectsService) DeleteProjectForkRelation(pid int) (*Response, error) ...@@ -900,12 +885,7 @@ func (s *ProjectsService) DeleteProjectForkRelation(pid int) (*Response, error)
return nil, err return nil, err
} }
resp, err := s.client.Do(req, nil) return s.client.Do(req, nil)
if err != nil {
return resp, err
}
return resp, err
} }
// Archives the project if the user is either admin or the project owner // Archives the project if the user is either admin or the project owner
......
...@@ -71,12 +71,7 @@ func (s *ServicesService) SetGitLabCIService( ...@@ -71,12 +71,7 @@ func (s *ServicesService) SetGitLabCIService(
return nil, err return nil, err
} }
resp, err := s.client.Do(req, nil) return s.client.Do(req, nil)
if err != nil {
return resp, err
}
return resp, err
} }
// DeleteGitLabCIService deletes GitLab CI service settings for a project. // DeleteGitLabCIService deletes GitLab CI service settings for a project.
...@@ -95,12 +90,7 @@ func (s *ServicesService) DeleteGitLabCIService(pid interface{}) (*Response, err ...@@ -95,12 +90,7 @@ func (s *ServicesService) DeleteGitLabCIService(pid interface{}) (*Response, err
return nil, err return nil, err
} }
resp, err := s.client.Do(req, nil) return s.client.Do(req, nil)
if err != nil {
return resp, err
}
return resp, err
} }
// SetHipChatServiceOptions represents the available SetHipChatService() // SetHipChatServiceOptions represents the available SetHipChatService()
...@@ -131,12 +121,7 @@ func (s *ServicesService) SetHipChatService( ...@@ -131,12 +121,7 @@ func (s *ServicesService) SetHipChatService(
return nil, err return nil, err
} }
resp, err := s.client.Do(req, nil) return s.client.Do(req, nil)
if err != nil {
return resp, err
}
return resp, err
} }
// DeleteHipChatService deletes HipChat service for project. // DeleteHipChatService deletes HipChat service for project.
...@@ -155,12 +140,7 @@ func (s *ServicesService) DeleteHipChatService(pid interface{}) (*Response, erro ...@@ -155,12 +140,7 @@ func (s *ServicesService) DeleteHipChatService(pid interface{}) (*Response, erro
return nil, err return nil, err
} }
resp, err := s.client.Do(req, nil) return s.client.Do(req, nil)
if err != nil {
return resp, err
}
return resp, err
} }
// SetDroneCIServiceOptions represents the available SetDroneCIService() // SetDroneCIServiceOptions represents the available SetDroneCIService()
...@@ -192,12 +172,7 @@ func (s *ServicesService) SetDroneCIService( ...@@ -192,12 +172,7 @@ func (s *ServicesService) SetDroneCIService(
return nil, err return nil, err
} }
resp, err := s.client.Do(req, nil) return s.client.Do(req, nil)
if err != nil {
return resp, err
}
return resp, err
} }
// DeleteDroneCIService deletes Drone CI service settings for a project. // DeleteDroneCIService deletes Drone CI service settings for a project.
...@@ -216,12 +191,7 @@ func (s *ServicesService) DeleteDroneCIService(pid interface{}) (*Response, erro ...@@ -216,12 +191,7 @@ func (s *ServicesService) DeleteDroneCIService(pid interface{}) (*Response, erro
return nil, err return nil, err
} }
resp, err := s.client.Do(req, nil) return s.client.Do(req, nil)
if err != nil {
return resp, err
}
return resp, err
} }
// DroneCIServiceProperties represents Drone CI specific properties. // DroneCIServiceProperties represents Drone CI specific properties.
...@@ -291,12 +261,7 @@ func (s *ServicesService) SetSlackService( ...@@ -291,12 +261,7 @@ func (s *ServicesService) SetSlackService(
return nil, err return nil, err
} }
resp, err := s.client.Do(req, nil) return s.client.Do(req, nil)
if err != nil {
return resp, err
}
return resp, err
} }
// DeleteSlackService deletes Slack service for project. // DeleteSlackService deletes Slack service for project.
...@@ -315,10 +280,5 @@ func (s *ServicesService) DeleteSlackService(pid interface{}) (*Response, error) ...@@ -315,10 +280,5 @@ func (s *ServicesService) DeleteSlackService(pid interface{}) (*Response, error)
return nil, err return nil, err
} }
resp, err := s.client.Do(req, nil) return s.client.Do(req, nil)
if err != nil {
return resp, err
}
return resp, err
} }
...@@ -19,7 +19,6 @@ package gitlab ...@@ -19,7 +19,6 @@ package gitlab
import ( import (
"bytes" "bytes"
"fmt" "fmt"
"io"
"reflect" "reflect"
) )
...@@ -35,9 +34,9 @@ func Stringify(message interface{}) string { ...@@ -35,9 +34,9 @@ func Stringify(message interface{}) string {
} }
// stringifyValue was heavily inspired by the goprotobuf library. // stringifyValue was heavily inspired by the goprotobuf library.
func stringifyValue(w io.Writer, val reflect.Value) { func stringifyValue(buf *bytes.Buffer, val reflect.Value) {
if val.Kind() == reflect.Ptr && val.IsNil() { if val.Kind() == reflect.Ptr && val.IsNil() {
w.Write([]byte("<nil>")) buf.WriteString("<nil>")
return return
} }
...@@ -45,25 +44,25 @@ func stringifyValue(w io.Writer, val reflect.Value) { ...@@ -45,25 +44,25 @@ func stringifyValue(w io.Writer, val reflect.Value) {
switch v.Kind() { switch v.Kind() {
case reflect.String: case reflect.String:
fmt.Fprintf(w, `"%s"`, v) fmt.Fprintf(buf, `"%s"`, v)
case reflect.Slice: case reflect.Slice:
w.Write([]byte{'['}) buf.WriteByte('[')
for i := 0; i < v.Len(); i++ { for i := 0; i < v.Len(); i++ {
if i > 0 { if i > 0 {
w.Write([]byte{' '}) buf.WriteByte(' ')
} }
stringifyValue(w, v.Index(i)) stringifyValue(buf, v.Index(i))
} }
w.Write([]byte{']'}) buf.WriteByte(']')
return return
case reflect.Struct: case reflect.Struct:
if v.Type().Name() != "" { if v.Type().Name() != "" {
w.Write([]byte(v.Type().String())) buf.WriteString(v.Type().String())
} }
w.Write([]byte{'{'}) buf.WriteByte('{')
var sep bool var sep bool
for i := 0; i < v.NumField(); i++ { for i := 0; i < v.NumField(); i++ {
...@@ -76,20 +75,20 @@ func stringifyValue(w io.Writer, val reflect.Value) { ...@@ -76,20 +75,20 @@ func stringifyValue(w io.Writer, val reflect.Value) {
} }
if sep { if sep {
w.Write([]byte(", ")) buf.WriteString(", ")
} else { } else {
sep = true sep = true
} }
w.Write([]byte(v.Type().Field(i).Name)) buf.WriteString(v.Type().Field(i).Name)
w.Write([]byte{':'}) buf.WriteByte(':')
stringifyValue(w, fv) stringifyValue(buf, fv)
} }
w.Write([]byte{'}'}) buf.WriteByte('}')
default: default:
if v.CanInterface() { if v.CanInterface() {
fmt.Fprint(w, v.Interface()) fmt.Fprint(buf, v.Interface())
} }
} }
} }
...@@ -139,10 +139,5 @@ func (s *SystemHooksService) DeleteHook(hook int) (*Response, error) { ...@@ -139,10 +139,5 @@ func (s *SystemHooksService) DeleteHook(hook int) (*Response, error) {
return nil, err return nil, err
} }
resp, err := s.client.Do(req, nil) return s.client.Do(req, nil)
if err != nil {
return resp, err
}
return resp, err
} }
...@@ -208,12 +208,7 @@ func (s *UsersService) DeleteUser(user int) (*Response, error) { ...@@ -208,12 +208,7 @@ func (s *UsersService) DeleteUser(user int) (*Response, error) {
return nil, err return nil, err
} }
resp, err := s.client.Do(req, nil) return s.client.Do(req, nil)
if err != nil {
return resp, err
}
return resp, err
} }
// CurrentUser gets currently authenticated user. // CurrentUser gets currently authenticated user.
...@@ -367,12 +362,7 @@ func (s *UsersService) DeleteSSHKey(kid int) (*Response, error) { ...@@ -367,12 +362,7 @@ func (s *UsersService) DeleteSSHKey(kid int) (*Response, error) {
return nil, err return nil, err
} }
resp, err := s.client.Do(req, nil) return s.client.Do(req, nil)
if err != nil {
return resp, err
}
return resp, err
} }
// DeleteSSHKeyForUser deletes key owned by a specified user. Available only // DeleteSSHKeyForUser deletes key owned by a specified user. Available only
...@@ -388,12 +378,7 @@ func (s *UsersService) DeleteSSHKeyForUser(user int, kid int) (*Response, error) ...@@ -388,12 +378,7 @@ func (s *UsersService) DeleteSSHKeyForUser(user int, kid int) (*Response, error)
return nil, err return nil, err
} }
resp, err := s.client.Do(req, nil) return s.client.Do(req, nil)
if err != nil {
return resp, err
}
return resp, err
} }
// BlockUser blocks the specified user. Available only for admin. // BlockUser blocks the specified user. Available only for admin.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment