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
go:
- 1.4.3
- 1.5.1
- 1.5.4
- 1.6.3
......@@ -201,10 +201,5 @@ func (s *BranchesService) DeleteBranch(pid interface{}, branch string) (*Respons
return nil, err
}
resp, err := s.client.Do(req, nil)
if err != nil {
return resp, err
}
return resp, err
return s.client.Do(req, nil)
}
......@@ -148,10 +148,5 @@ func (s *DeployKeysService) DeleteDeployKey(pid interface{}, deployKey int) (*Re
return nil, err
}
resp, err := s.client.Do(req, nil)
if err != nil {
return resp, err
}
return resp, err
return s.client.Do(req, nil)
}
......@@ -210,11 +210,7 @@ func (c *Client) SetBaseURL(urlStr string) error {
var err error
c.baseURL, err = url.Parse(urlStr)
if err != nil {
return err
}
return nil
return err
}
// 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) {
return nil, err
}
resp, err := s.client.Do(req, nil)
if err != nil {
return resp, err
}
return resp, err
return s.client.Do(req, nil)
}
// 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,
return nil, err
}
resp, err := s.client.Do(req, nil)
if err != nil {
return resp, err
}
return resp, err
return s.client.Do(req, nil)
}
......@@ -273,10 +273,5 @@ func (s *IssuesService) DeleteIssue(pid interface{}, issue int) (*Response, erro
return nil, err
}
resp, err := s.client.Do(req, nil)
if err != nil {
return resp, err
}
return resp, err
return s.client.Do(req, nil)
}
......@@ -127,12 +127,7 @@ func (s *LabelsService) DeleteLabel(pid interface{}, opt *DeleteLabelOptions) (*
return nil, err
}
resp, err := s.client.Do(req, nil)
if err != nil {
return resp, err
}
return resp, err
return s.client.Do(req, nil)
}
// UpdateLabelOptions represents the available UpdateLabel() options.
......
......@@ -212,12 +212,7 @@ func (s *ProjectSnippetsService) DeleteSnippet(pid interface{}, snippet int) (*R
return nil, err
}
resp, err := s.client.Do(req, nil)
if err != nil {
return resp, err
}
return resp, err
return s.client.Do(req, nil)
}
// SnippetContent returns the raw project snippet as plain text.
......
......@@ -488,12 +488,7 @@ func (s *ProjectsService) DeleteProject(pid interface{}) (*Response, error) {
return nil, err
}
resp, err := s.client.Do(req, nil)
if err != nil {
return resp, err
}
return resp, err
return s.client.Do(req, nil)
}
// ProjectMember represents a project member.
......@@ -665,12 +660,7 @@ func (s *ProjectsService) DeleteProjectMember(pid interface{}, user int) (*Respo
return nil, err
}
resp, err := s.client.Do(req, nil)
if err != nil {
return resp, err
}
return resp, err
return s.client.Do(req, nil)
}
// ProjectHook represents a project hook.
......@@ -844,12 +834,7 @@ func (s *ProjectsService) DeleteProjectHook(pid interface{}, hook int) (*Respons
return nil, err
}
resp, err := s.client.Do(req, nil)
if err != nil {
return resp, err
}
return resp, err
return s.client.Do(req, nil)
}
// ProjectForkRelation represents a project fork relationship.
......@@ -900,12 +885,7 @@ func (s *ProjectsService) DeleteProjectForkRelation(pid int) (*Response, error)
return nil, err
}
resp, err := s.client.Do(req, nil)
if err != nil {
return resp, err
}
return resp, err
return s.client.Do(req, nil)
}
// Archives the project if the user is either admin or the project owner
......
......@@ -71,12 +71,7 @@ func (s *ServicesService) SetGitLabCIService(
return nil, err
}
resp, err := s.client.Do(req, nil)
if err != nil {
return resp, err
}
return resp, err
return s.client.Do(req, nil)
}
// DeleteGitLabCIService deletes GitLab CI service settings for a project.
......@@ -95,12 +90,7 @@ func (s *ServicesService) DeleteGitLabCIService(pid interface{}) (*Response, err
return nil, err
}
resp, err := s.client.Do(req, nil)
if err != nil {
return resp, err
}
return resp, err
return s.client.Do(req, nil)
}
// SetHipChatServiceOptions represents the available SetHipChatService()
......@@ -131,12 +121,7 @@ func (s *ServicesService) SetHipChatService(
return nil, err
}
resp, err := s.client.Do(req, nil)
if err != nil {
return resp, err
}
return resp, err
return s.client.Do(req, nil)
}
// DeleteHipChatService deletes HipChat service for project.
......@@ -155,12 +140,7 @@ func (s *ServicesService) DeleteHipChatService(pid interface{}) (*Response, erro
return nil, err
}
resp, err := s.client.Do(req, nil)
if err != nil {
return resp, err
}
return resp, err
return s.client.Do(req, nil)
}
// SetDroneCIServiceOptions represents the available SetDroneCIService()
......@@ -169,9 +149,9 @@ func (s *ServicesService) DeleteHipChatService(pid interface{}) (*Response, erro
// GitLab API docs:
// http://doc.gitlab.com/ce/api/services.html#createedit-drone-ci-service
type SetDroneCIServiceOptions struct {
Token *string `url:"token" json:"token" `
DroneURL *string `url:"drone_url" json:"drone_url"`
EnableSSLVerification *string `url:"enable_ssl_verification,omitempty" json:"enable_ssl_verification,omitempty"`
Token *string `url:"token" json:"token" `
DroneURL *string `url:"drone_url" json:"drone_url"`
EnableSSLVerification *string `url:"enable_ssl_verification,omitempty" json:"enable_ssl_verification,omitempty"`
}
// SetDroneCIService sets Drone CI service for a project.
......@@ -192,12 +172,7 @@ func (s *ServicesService) SetDroneCIService(
return nil, err
}
resp, err := s.client.Do(req, nil)
if err != nil {
return resp, err
}
return resp, err
return s.client.Do(req, nil)
}
// DeleteDroneCIService deletes Drone CI service settings for a project.
......@@ -216,19 +191,14 @@ func (s *ServicesService) DeleteDroneCIService(pid interface{}) (*Response, erro
return nil, err
}
resp, err := s.client.Do(req, nil)
if err != nil {
return resp, err
}
return resp, err
return s.client.Do(req, nil)
}
// DroneCIServiceProperties represents Drone CI specific properties.
type DroneCIServiceProperties struct {
Token *string `url:"token" json:"token"`
DroneURL *string `url:"drone_url" json:"drone_url"`
EnableSSLVerification *string `url:"enable_ssl_verification" json:"enable_ssl_verification"`
Token *string `url:"token" json:"token"`
DroneURL *string `url:"drone_url" json:"drone_url"`
EnableSSLVerification *string `url:"enable_ssl_verification" json:"enable_ssl_verification"`
}
// DroneCIService represents Drone CI service settings.
......@@ -291,12 +261,7 @@ func (s *ServicesService) SetSlackService(
return nil, err
}
resp, err := s.client.Do(req, nil)
if err != nil {
return resp, err
}
return resp, err
return s.client.Do(req, nil)
}
// DeleteSlackService deletes Slack service for project.
......@@ -315,10 +280,5 @@ func (s *ServicesService) DeleteSlackService(pid interface{}) (*Response, error)
return nil, err
}
resp, err := s.client.Do(req, nil)
if err != nil {
return resp, err
}
return resp, err
return s.client.Do(req, nil)
}
......@@ -19,7 +19,6 @@ package gitlab
import (
"bytes"
"fmt"
"io"
"reflect"
)
......@@ -35,9 +34,9 @@ func Stringify(message interface{}) string {
}
// 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() {
w.Write([]byte("<nil>"))
buf.WriteString("<nil>")
return
}
......@@ -45,25 +44,25 @@ func stringifyValue(w io.Writer, val reflect.Value) {
switch v.Kind() {
case reflect.String:
fmt.Fprintf(w, `"%s"`, v)
fmt.Fprintf(buf, `"%s"`, v)
case reflect.Slice:
w.Write([]byte{'['})
buf.WriteByte('[')
for i := 0; i < v.Len(); i++ {
if i > 0 {
w.Write([]byte{' '})
buf.WriteByte(' ')
}
stringifyValue(w, v.Index(i))
stringifyValue(buf, v.Index(i))
}
w.Write([]byte{']'})
buf.WriteByte(']')
return
case reflect.Struct:
if v.Type().Name() != "" {
w.Write([]byte(v.Type().String()))
buf.WriteString(v.Type().String())
}
w.Write([]byte{'{'})
buf.WriteByte('{')
var sep bool
for i := 0; i < v.NumField(); i++ {
......@@ -76,20 +75,20 @@ func stringifyValue(w io.Writer, val reflect.Value) {
}
if sep {
w.Write([]byte(", "))
buf.WriteString(", ")
} else {
sep = true
}
w.Write([]byte(v.Type().Field(i).Name))
w.Write([]byte{':'})
stringifyValue(w, fv)
buf.WriteString(v.Type().Field(i).Name)
buf.WriteByte(':')
stringifyValue(buf, fv)
}
w.Write([]byte{'}'})
buf.WriteByte('}')
default:
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) {
return nil, err
}
resp, err := s.client.Do(req, nil)
if err != nil {
return resp, err
}
return resp, err
return s.client.Do(req, nil)
}
......@@ -208,12 +208,7 @@ func (s *UsersService) DeleteUser(user int) (*Response, error) {
return nil, err
}
resp, err := s.client.Do(req, nil)
if err != nil {
return resp, err
}
return resp, err
return s.client.Do(req, nil)
}
// CurrentUser gets currently authenticated user.
......@@ -367,12 +362,7 @@ func (s *UsersService) DeleteSSHKey(kid int) (*Response, error) {
return nil, err
}
resp, err := s.client.Do(req, nil)
if err != nil {
return resp, err
}
return resp, err
return s.client.Do(req, nil)
}
// DeleteSSHKeyForUser deletes key owned by a specified user. Available only
......@@ -388,12 +378,7 @@ func (s *UsersService) DeleteSSHKeyForUser(user int, kid int) (*Response, error)
return nil, err
}
resp, err := s.client.Do(req, nil)
if err != nil {
return resp, err
}
return resp, err
return s.client.Do(req, nil)
}
// 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