Skip to content

Commit

Permalink
Bump go version (#165)
Browse files Browse the repository at this point in the history
* Bump go version

I ran go mod tidy

Signed-off-by: György Krajcsovits <[email protected]>

* Bump golangci-lint and fix deprecations

Signed-off-by: György Krajcsovits <[email protected]>

---------

Signed-off-by: György Krajcsovits <[email protected]>
  • Loading branch information
krajorama authored Apr 5, 2024
1 parent 4263bce commit 1f60098
Show file tree
Hide file tree
Showing 14 changed files with 101 additions and 33 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ jobs:
- name: install Go
uses: actions/setup-go@v5
with:
go-version: 1.18.x
go-version: 1.22.x
- name: Install snmp_exporter/generator dependencies
run: sudo apt-get update && sudo apt-get -y install libsnmp-dev
if: github.repository == 'prometheus/snmp_exporter'
- name: Lint
uses: golangci/[email protected]
with:
version: v1.50.1
version: v1.56.2
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ The mixtool is a helper for easily working with [jsonnet](http://jsonnet.org/) m

## Install

Make sure you're using golang v1.17 or higher, and run:
Make sure you're using golang v1.21 or higher, and run:

```
go install github.com/monitoring-mixins/mixtool/cmd/mixtool@main
Expand Down
5 changes: 2 additions & 3 deletions cmd/mixtool/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"path/filepath"

Expand Down Expand Up @@ -143,15 +142,15 @@ func generateAlerts(filename string, options mixer.GenerateOptions) error {
return err
}

return ioutil.WriteFile(options.AlertsFilename, out, 0644)
return os.WriteFile(options.AlertsFilename, out, 0644)
}

func generateRules(filename string, options mixer.GenerateOptions) error {
out, err := mixer.GenerateRules(filename, options)
if err != nil {
return err
}
return ioutil.WriteFile(options.RulesFilename, out, 0644)
return os.WriteFile(options.RulesFilename, out, 0644)
}

func generateDashboards(filename string, opts mixer.GenerateOptions) error {
Expand Down
4 changes: 2 additions & 2 deletions cmd/mixtool/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package main
import (
"bytes"
"fmt"
"io/ioutil"
"io"
"net/http"
"net/url"
"os"
Expand Down Expand Up @@ -145,7 +145,7 @@ func putMixin(content []byte, bindAddress string) error {
if resp.StatusCode == 200 {
fmt.Println("PUT alerts OK")
} else {
responseData, err := ioutil.ReadAll(resp.Body)
responseData, err := io.ReadAll(resp.Body)
if err != nil {
return fmt.Errorf("failed to response body in putMixin, %w", err)
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/mixtool/install_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package main

import (
"fmt"
"io/ioutil"
"os"
"path"
"testing"
Expand Down Expand Up @@ -48,7 +47,7 @@ func TestInstallMixin(t *testing.T) {
}

func testInstallMixin(t *testing.T, m mixin) {
tmpdir, err := ioutil.TempDir("", "mixtool-install")
tmpdir, err := os.MkdirTemp("", "mixtool-install")
assert.NoError(t, err)
defer os.RemoveAll(tmpdir)

Expand Down
6 changes: 3 additions & 3 deletions cmd/mixtool/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"net/url"
"os"
Expand Down Expand Up @@ -68,7 +68,7 @@ func queryWebsite(mixinsWebsite string) ([]byte, error) {
return nil, err
}
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
body, err := io.ReadAll(res.Body)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -129,7 +129,7 @@ func listAction(c *cli.Context) error {
if err != nil {
return err
}
body, err = ioutil.ReadFile(path)
body, err = os.ReadFile(path)
if err != nil {
return err
}
Expand Down
7 changes: 3 additions & 4 deletions cmd/mixtool/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
package main

import (
"io/ioutil"
"os"
"testing"

Expand Down Expand Up @@ -47,14 +46,14 @@ const exampleMixins = `
`

func TestList(t *testing.T) {
tempFile, err := ioutil.TempFile("", "exampleMixinsTest.json")
tempFile, err := os.CreateTemp("", "exampleMixinsTest.json")
assert.NoError(t, err)
defer os.Remove(tempFile.Name())

err = ioutil.WriteFile(tempFile.Name(), []byte(exampleMixins), 0644)
err = os.WriteFile(tempFile.Name(), []byte(exampleMixins), 0644)
assert.NoError(t, err)

body, err := ioutil.ReadFile(tempFile.Name())
body, err := os.ReadFile(tempFile.Name())
assert.NoError(t, err)

mixins, err := parseMixinJSON([]byte(body))
Expand Down
7 changes: 3 additions & 4 deletions cmd/mixtool/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"net/http"
"os"
"path/filepath"
Expand Down Expand Up @@ -99,12 +98,12 @@ type ruleProvisioner struct {
// to existing, does not provision them. It returns whether Prometheus should
// be reloaded and if an error has occurred.
func (p *ruleProvisioner) provision(r io.Reader) (bool, error) {
newData, err := ioutil.ReadAll(r)
newData, err := io.ReadAll(r)
if err != nil {
return false, fmt.Errorf("unable to read new rules: %w", err)
}

tempfile, err := ioutil.TempFile(filepath.Dir(p.ruleFile), "temp-mixtool")
tempfile, err := os.CreateTemp(filepath.Dir(p.ruleFile), "temp-mixtool")
if err != nil {
return false, fmt.Errorf("unable to create temp file: %w", err)
}
Expand Down Expand Up @@ -184,7 +183,7 @@ func (r *prometheusReloader) triggerReload(ctx context.Context) error {
return fmt.Errorf("reload request: %w", err)
}

if _, err := io.Copy(ioutil.Discard, resp.Body); err != nil {
if _, err := io.Copy(io.Discard, resp.Body); err != nil {
return fmt.Errorf("exhausting request body: %w", err)
}

Expand Down
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module github.com/monitoring-mixins/mixtool

go 1.18
go 1.21

toolchain go1.21.8

require (
github.com/fatih/color v1.16.0
Expand Down
Loading

0 comments on commit 1f60098

Please sign in to comment.