From d9e41f18ad3409193d43c9c8ee8f579a1dd14b79 Mon Sep 17 00:00:00 2001 From: Julien Brochet Date: Thu, 11 May 2023 19:26:19 +0200 Subject: [PATCH] chore: small changes --- .github/workflows/release.yml | 2 +- .github/workflows/test.yml | 6 +++--- LICENSE | 2 +- config/config.go | 8 ++++---- go.mod | 8 ++++---- go.sum | 16 ++++++++-------- ip/client.go | 8 +++++--- scaleway/dns.go | 11 +++++------ tests/web.go | 2 +- 9 files changed, 32 insertions(+), 31 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 60ff853..c2081a8 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -17,7 +17,7 @@ jobs: - name: Setup Go uses: actions/setup-go@v3 with: - go-version: 1.20 + go-version: '1.20' - name: Set up Docker Buildx uses: docker/setup-buildx-action@v2.5.0 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 54a7ddc..bcbf1b7 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -7,8 +7,8 @@ jobs: name: Test strategy: matrix: - go-version: [1.20] - platform: [ubuntu-latest, macos-latest, windows-latest] + go: [ '1.20' ] + platform: [ ubuntu-latest, macos-latest, windows-latest ] runs-on: ${{ matrix.platform }} steps: - name: Checkout @@ -17,7 +17,7 @@ jobs: - name: Setup Go uses: actions/setup-go@v3 with: - go-version: ${{ matrix.go-version }} + go-version: ${{ matrix.go }} - name: Test run: go test ./... diff --git a/LICENSE b/LICENSE index 0dd2519..2ad443f 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2020-2022 Julien Brochet +Copyright (c) 2020-2023 Julien Brochet Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/config/config.go b/config/config.go index c6c52aa..b2ab3fa 100644 --- a/config/config.go +++ b/config/config.go @@ -2,22 +2,22 @@ package config import ( "fmt" - "io/ioutil" + "os" "gopkg.in/yaml.v2" ) // NewConfig returns a new config object if the file exists func NewConfig(path string) (*Config, error) { - data, err := ioutil.ReadFile(path) + data, err := os.ReadFile(path) if err != nil { - return nil, fmt.Errorf("unable to load the config from file (%s)", err) + return nil, fmt.Errorf("unable to load the config from file %s: %w", path, err) } cfg := &Config{} *cfg = DefaultConfig - err = yaml.Unmarshal([]byte(data), &cfg) + err = yaml.Unmarshal(data, &cfg) if err != nil { return nil, err } diff --git a/go.mod b/go.mod index 94a7433..c1760b6 100644 --- a/go.mod +++ b/go.mod @@ -4,9 +4,9 @@ go 1.20 require ( github.com/go-telegram-bot-api/telegram-bot-api v4.6.4+incompatible - github.com/scaleway/scaleway-sdk-go v1.0.0-beta.14 + github.com/scaleway/scaleway-sdk-go v1.0.0-beta.16 github.com/sirupsen/logrus v1.9.0 - github.com/spf13/cobra v1.6.1 + github.com/spf13/cobra v1.7.0 github.com/stretchr/testify v1.8.2 github.com/technoweenie/multipartstreamer v1.0.1 // indirect gopkg.in/yaml.v2 v2.4.0 @@ -14,9 +14,9 @@ require ( require ( github.com/davecgh/go-spew v1.1.1 // indirect - github.com/inconshreveable/mousetrap v1.0.1 // indirect + github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/spf13/pflag v1.0.5 // indirect - golang.org/x/sys v0.0.0-20220829200755-d48e67d00261 // indirect + golang.org/x/sys v0.8.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index c054955..bcdf5c0 100644 --- a/go.sum +++ b/go.sum @@ -4,17 +4,17 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/go-telegram-bot-api/telegram-bot-api v4.6.4+incompatible h1:2cauKuaELYAEARXRkq2LrJ0yDDv1rW7+wrTEdVL3uaU= github.com/go-telegram-bot-api/telegram-bot-api v4.6.4+incompatible/go.mod h1:qf9acutJ8cwBUhm1bqgz6Bei9/C/c93FPDljKWwsOgM= -github.com/inconshreveable/mousetrap v1.0.1 h1:U3uMjPSQEBMNp1lFxmllqCPM6P5u/Xq7Pgzkat/bFNc= -github.com/inconshreveable/mousetrap v1.0.1/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= +github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= +github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= -github.com/scaleway/scaleway-sdk-go v1.0.0-beta.14 h1:yFl3jyaSVLNYXlnNYM5z2pagEk1dYQhfr1p20T1NyKY= -github.com/scaleway/scaleway-sdk-go v1.0.0-beta.14/go.mod h1:fCa7OJZ/9DRTnOKmxvT6pn+LPWUptQAmHF/SBJUGEcg= +github.com/scaleway/scaleway-sdk-go v1.0.0-beta.16 h1:Ted1/3BGV1d0c7J+69N+brveAgJNWZlWnI8iYP3dZMs= +github.com/scaleway/scaleway-sdk-go v1.0.0-beta.16/go.mod h1:fCa7OJZ/9DRTnOKmxvT6pn+LPWUptQAmHF/SBJUGEcg= github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0= github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= -github.com/spf13/cobra v1.6.1 h1:o94oiPyS4KD1mPy2fmcYYHHfCxLqYjJOhGsCHFZtEzA= -github.com/spf13/cobra v1.6.1/go.mod h1:IOw/AERYS7UzyrGinqmz6HLUo219MORXGxhbaJUqzrY= +github.com/spf13/cobra v1.7.0 h1:hyqWnYt1ZQShIddO5kBpj3vu05/++x6tJ6dg8EC572I= +github.com/spf13/cobra v1.7.0/go.mod h1:uLxZILRyS/50WlhOIKD7W6V5bgeIt+4sICxh6uRMrb0= github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= @@ -28,8 +28,8 @@ github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o github.com/technoweenie/multipartstreamer v1.0.1 h1:XRztA5MXiR1TIRHxH2uNxXxaIkKQDeX7m2XsSOlQEnM= github.com/technoweenie/multipartstreamer v1.0.1/go.mod h1:jNVxdtShOxzAsukZwTSw6MDx5eUJoiEBsSvzDU9uzog= golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220829200755-d48e67d00261 h1:v6hYoSR9T5oet+pMXwUWkbiVqx/63mlHjefrHmxwfeY= -golang.org/x/sys v0.0.0-20220829200755-d48e67d00261/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU= +golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= diff --git a/ip/client.go b/ip/client.go index 194680f..3393f6a 100644 --- a/ip/client.go +++ b/ip/client.go @@ -3,7 +3,7 @@ package ip import ( "errors" "fmt" - "io/ioutil" + "io" "net" "net/http" "strings" @@ -16,13 +16,15 @@ func GetPublicIP(url string) (string, error) { return "", err } - defer response.Body.Close() + defer func(Body io.ReadCloser) { + _ = Body.Close() + }(response.Body) if response.StatusCode != http.StatusOK { return "", fmt.Errorf("unable to get public IP from endpoint %s", url) } - body, err := ioutil.ReadAll(response.Body) + body, err := io.ReadAll(response.Body) if err != nil { return "", err } diff --git a/scaleway/dns.go b/scaleway/dns.go index 02f0b1a..146466b 100644 --- a/scaleway/dns.go +++ b/scaleway/dns.go @@ -114,13 +114,12 @@ func (d *DNS) GetRecord(domain string, name string, recordType string) (*domainA } func (d *DNS) getRecordTypeFromString(recordType string) domainAPI.RecordType { - if recordType == "A" { + switch recordType { + case "A": return domainAPI.RecordTypeA - } - - if recordType == "AAAA" { + case "AAAA": return domainAPI.RecordTypeAAAA + default: + return domainAPI.RecordTypeUnknown } - - return domainAPI.RecordTypeUnknown } diff --git a/tests/web.go b/tests/web.go index 31e11f3..818d833 100644 --- a/tests/web.go +++ b/tests/web.go @@ -11,7 +11,7 @@ func StartWebServer(requests map[string]string) *httptest.Server { return httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { for uri, content := range requests { if r.RequestURI == uri { - fmt.Fprintln(w, content) + _, _ = fmt.Fprintln(w, content) } } }))