Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add golangci and update go version in workflows #235

Merged
merged 3 commits into from
Dec 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: 1.17
go-version: 1.19

- name: Run unit tests and coverage test
id: test-coverage
Expand Down Expand Up @@ -62,4 +62,3 @@ jobs:
repo: context.repo.repo,
body: output
})

17 changes: 5 additions & 12 deletions .github/workflows/gochecks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,16 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: '1.17'
go-version: '1.19'

- name: Install dependencies
run: |
go version
go get -u golang.org/x/lint/golint
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.49.0

- name: Run Lint
- name: Run golangci-lint
run: |
golint_files=$(golint .)
if [[ -n ${golint_files} ]]; then
echo 'fix the following linting errors:'
echo "${golint_files}"
exit 1
fi
exit 0
golangci-lint run ./...

Go-Fmt:
runs-on: ubuntu-latest
Expand All @@ -42,7 +36,7 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: '1.17'
go-version: '1.19'

- name: Run fmt
run: |
Expand All @@ -53,4 +47,3 @@ jobs:
exit 1
fi
exit 0

2 changes: 1 addition & 1 deletion .github/workflows/releaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ jobs:
name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.17
go-version: 1.19
-
name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
Expand Down
12 changes: 3 additions & 9 deletions govultr.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"io"
"net/http"
"net/url"
"strings"
Expand All @@ -23,12 +23,6 @@ const (
retryLimit = 3
)

// APIKey contains a users API Key for interacting with the API
type APIKey struct {
// API Key
key string
}

// RequestBody is used to create JSON bodies for one off calls
type RequestBody map[string]interface{}

Expand Down Expand Up @@ -177,7 +171,7 @@ func (c *Client) DoWithContext(ctx context.Context, r *http.Request, data interf

defer res.Body.Close()

body, err := ioutil.ReadAll(res.Body)
body, err := io.ReadAll(res.Body)
if err != nil {
return err
}
Expand Down Expand Up @@ -236,7 +230,7 @@ func (c *Client) vultrErrorHandler(resp *http.Response, err error, numTries int)
return nil, fmt.Errorf("gave up after %d attempts, last error unavailable (resp == nil)", numTries)
}

buf, err := ioutil.ReadAll(resp.Body)
buf, err := io.ReadAll(resp.Body)
if err != nil {
return nil, fmt.Errorf("gave up after %d attempts, last error unavailable (error reading response body: %v)", numTries, err)
}
Expand Down
8 changes: 5 additions & 3 deletions govultr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"errors"
"fmt"
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
"net/http/httputil"
Expand Down Expand Up @@ -141,7 +141,9 @@ func TestClient_DoWithContextError(t *testing.T) {
panicked = fmt.Sprint(err)
}
}()
client.DoWithContext(context.Background(), req, nil)
if err := client.DoWithContext(context.Background(), req, nil); err != nil {
t.Errorf("dowithcontext error: %s", err)
}
}()
if panicked != "" {
t.Errorf("unexpected panic: %s", panicked)
Expand All @@ -162,7 +164,7 @@ func TestClient_NewRequest(t *testing.T) {
t.Errorf("NewRequest(%v) URL = %v, expected %v", in, req.URL, out)
}

body, _ := ioutil.ReadAll(req.Body)
body, _ := io.ReadAll(req.Body)

if string(body) != outRequest {
t.Errorf("NewRequest(%v)Body = %v, expected %v", inRequest, string(body), outRequest)
Expand Down
4 changes: 1 addition & 3 deletions instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,9 +294,7 @@ type ReinstallReq struct {

// Create will create the server with the given parameters
func (i *InstanceServiceHandler) Create(ctx context.Context, instanceReq *InstanceCreateReq) (*Instance, error) {
uri := fmt.Sprintf("%s", instancePath)

req, err := i.client.NewRequest(ctx, http.MethodPost, uri, instanceReq)
req, err := i.client.NewRequest(ctx, http.MethodPost, instancePath, instanceReq)
if err != nil {
return nil, err
}
Expand Down
8 changes: 4 additions & 4 deletions instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package govultr

import (
"fmt"
"io/ioutil"
"io"
"net/http"
"reflect"
"testing"
Expand Down Expand Up @@ -79,7 +79,7 @@ func TestServerServiceHandler_RestoreSnapshot(t *testing.T) {
defer teardown()

mux.HandleFunc("/v2/instances/14b3e7d6-ffb5-4994-8502-57fcd9db3b33/restore", func(writer http.ResponseWriter, request *http.Request) {
body, err := ioutil.ReadAll(request.Body)
body, err := io.ReadAll(request.Body)
if err != nil || len(body) == 0 {
http.Error(writer, "can't read body", http.StatusBadRequest)
return
Expand Down Expand Up @@ -363,7 +363,7 @@ func TestServerServiceHandler_GetBandwidth(t *testing.T) {
"outgoing_bytes": 3084731
}
}
}
}
`
fmt.Fprint(writer, response)
})
Expand Down Expand Up @@ -758,7 +758,7 @@ func TestServerServiceHandler_List(t *testing.T) {
"next":"thisismycusror",
"prev":""
}
}
}
}`
fmt.Fprint(writer, response)
})
Expand Down
26 changes: 13 additions & 13 deletions kubernetes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func TestKubernetesHandler_CreateCluster(t *testing.T) {
]
}
}`
fmt.Fprintf(writer, response)
fmt.Fprint(writer, response)
})

createReq := &ClusterReq{
Expand Down Expand Up @@ -149,7 +149,7 @@ func TestKubernetesHandler_GetCluster(t *testing.T) {
]
}
}`
fmt.Fprintf(writer, response)
fmt.Fprint(writer, response)
})

vke, err := client.Kubernetes.GetCluster(ctx, "014da059-21e3-47eb-acb5-91bf697c31aa")
Expand Down Expand Up @@ -207,7 +207,7 @@ func TestKubernetesHandler_ListClusters(t *testing.T) {
setup()
defer teardown()

mux.HandleFunc(fmt.Sprintf("%s", vkePath), func(writer http.ResponseWriter, request *http.Request) {
mux.HandleFunc(vkePath, func(writer http.ResponseWriter, request *http.Request) {
response := `{
"vke_clusters": [{
"id": "014da059-21e3-47eb-acb5-91bf697c31aa",
Expand Down Expand Up @@ -252,7 +252,7 @@ func TestKubernetesHandler_ListClusters(t *testing.T) {
}
}
}`
fmt.Fprintf(writer, response)
fmt.Fprint(writer, response)
})

vke, meta, err := client.Kubernetes.ListClusters(ctx, nil)
Expand Down Expand Up @@ -389,7 +389,7 @@ func TestKubernetesHandler_CreateNodePool(t *testing.T) {
]
}
}`
fmt.Fprintf(writer, response)
fmt.Fprint(writer, response)
})

createReq := &NodePoolReq{
Expand Down Expand Up @@ -463,7 +463,7 @@ func TestKubernetesHandler_GetNodePool(t *testing.T) {
]
}
}`
fmt.Fprintf(writer, response)
fmt.Fprint(writer, response)
})

np, err := client.Kubernetes.GetNodePool(ctx, "1", "2")
Expand Down Expand Up @@ -538,7 +538,7 @@ func TestKubernetesHandler_ListNodePools(t *testing.T) {
}
}
}`
fmt.Fprintf(writer, response)
fmt.Fprint(writer, response)
})

np, meta, err := client.Kubernetes.ListNodePools(ctx, "1", nil)
Expand Down Expand Up @@ -621,7 +621,7 @@ func TestKubernetesHandler_UpdateNodePool(t *testing.T) {
]
}
}`
fmt.Fprintf(writer, response)
fmt.Fprint(writer, response)
})
update := NodePoolReqUpdate{NodeQuantity: 1}
response, err := client.Kubernetes.UpdateNodePool(ctx, "1", "2", &update)
Expand Down Expand Up @@ -681,7 +681,7 @@ func TestKubernetesHandler_DeleteNodePoolInstance(t *testing.T) {
setup()
defer teardown()
path := fmt.Sprintf("%s/%s/node-pools/%s/nodes/%s", vkePath, "1", "2", "3")
mux.HandleFunc(fmt.Sprintf(path), func(writer http.ResponseWriter, request *http.Request) {
mux.HandleFunc(path, func(writer http.ResponseWriter, request *http.Request) {
fmt.Fprint(writer)
})

Expand All @@ -695,7 +695,7 @@ func TestKubernetesHandler_RecycleNodePoolInstance(t *testing.T) {
setup()
defer teardown()
path := fmt.Sprintf("%s/%s/node-pools/%s/nodes/%s/recycle", vkePath, "1", "2", "3")
mux.HandleFunc(fmt.Sprintf(path), func(writer http.ResponseWriter, request *http.Request) {
mux.HandleFunc(path, func(writer http.ResponseWriter, request *http.Request) {
fmt.Fprint(writer)
})

Expand All @@ -709,7 +709,7 @@ func TestKubernetesHandler_GetKubeConfig(t *testing.T) {
setup()
defer teardown()
path := fmt.Sprintf("%s/%s/config", vkePath, "1")
mux.HandleFunc(fmt.Sprintf(path), func(writer http.ResponseWriter, request *http.Request) {
mux.HandleFunc(path, func(writer http.ResponseWriter, request *http.Request) {
response := `{"kube_config": "config="}`
fmt.Fprint(writer, response)
})
Expand All @@ -736,7 +736,7 @@ func TestKubernetesHandler_GetVersions(t *testing.T) {
setup()
defer teardown()
path := "/v2/kubernetes/versions"
mux.HandleFunc(fmt.Sprintf(path), func(writer http.ResponseWriter, request *http.Request) {
mux.HandleFunc(path, func(writer http.ResponseWriter, request *http.Request) {
response := `{"versions": ["v1.20.0+1"]}`
fmt.Fprint(writer, response)
})
Expand All @@ -763,7 +763,7 @@ func TestKubernetesHandler_GetUpgrades(t *testing.T) {
setup()
defer teardown()
path := fmt.Sprintf("%s/%s/available-upgrades", vkePath, "1")
mux.HandleFunc(fmt.Sprintf(path), func(writer http.ResponseWriter, request *http.Request) {
mux.HandleFunc(path, func(writer http.ResponseWriter, request *http.Request) {
response := `{"available_upgrades": ["v1.20.0+1"]}`
fmt.Fprint(writer, response)
})
Expand Down
16 changes: 8 additions & 8 deletions load_balancer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func TestLoadBalancerHandler_List(t *testing.T) {
"source": "0.0.0.0/0",
"ip_type": "v4"
}
],
],
"instances": [
"12345"
]
Expand All @@ -74,7 +74,7 @@ func TestLoadBalancerHandler_List(t *testing.T) {
}
}
`
fmt.Fprintf(writer, response)
fmt.Fprint(writer, response)
})

list, meta, err := client.LoadBalancer.List(ctx, nil)
Expand Down Expand Up @@ -214,14 +214,14 @@ func TestLoadBalancerHandler_Get(t *testing.T) {
"source": "0.0.0.0/0",
"ip_type": "v4"
}
],
],
"instances": [
"12345"
]
}
}
`
fmt.Fprintf(writer, response)
fmt.Fprint(writer, response)
})

info, err := client.LoadBalancer.Get(ctx, "1317575")
Expand Down Expand Up @@ -307,7 +307,7 @@ func TestLoadBalancerHandler_ListForwardingRules(t *testing.T) {
}
}
`
fmt.Fprintf(writer, response)
fmt.Fprint(writer, response)
})

list, meta, err := client.LoadBalancer.ListForwardingRules(ctx, "12345", nil)
Expand Down Expand Up @@ -371,7 +371,7 @@ func TestLoadBalancerHandler_CreateForwardingRule(t *testing.T) {
}
}
`
fmt.Fprintf(writer, response)
fmt.Fprint(writer, response)
})

rule := &ForwardingRule{
Expand Down Expand Up @@ -452,14 +452,14 @@ func TestLoadBalancerHandler_Create(t *testing.T) {
"source": "0.0.0.0/0",
"ip_type": "v4"
}
],
],
"instances": [
"1234"
]
}
}
`
fmt.Fprintf(writer, response)
fmt.Fprint(writer, response)
})

lbCreate := &LoadBalancerReq{
Expand Down
2 changes: 1 addition & 1 deletion network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func TestNetworkServiceHandler_List(t *testing.T) {
}]
}
`
fmt.Fprintf(writer, response)
fmt.Fprint(writer, response)
})

networks, _, err := client.Network.List(ctx, nil)
Expand Down
Loading