Skip to content

Commit

Permalink
Merge pull request #39 from grisu48/modernize
Browse files Browse the repository at this point in the history
Deprecate ioutil
  • Loading branch information
grisu48 authored Apr 4, 2024
2 parents ebfdcb4 + ec0410b commit d24ff1f
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/gopenqa.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- name: Setup go
uses: actions/setup-go@v5
with:
go-version: '1.14'
go-version: '1.16'
- name: Install requirements
run: go get github.com/streadway/amqp
- name: Run test suite
Expand Down
2 changes: 1 addition & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
image: golang:1.14
image: golang:1.16

test:
script:
Expand Down
20 changes: 10 additions & 10 deletions cmd/gopenqa/gopenqa.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"bufio"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"os"
"strconv"
"strings"
Expand Down Expand Up @@ -150,18 +150,18 @@ func readMachines(filename string) ([]gopenqa.Machine, error) {
var err error

if filename == "" {
data, err = ioutil.ReadAll(os.Stdin)
data, err = io.ReadAll(os.Stdin)
if err != nil {
machines := make([]gopenqa.Machine, 0)
return machines, err
}
} else {
// TODO: Don't use ioutil.ReadAll
// TODO: Don't use io.ReadAll
if file, err := os.Open(filename); err != nil {
return make([]gopenqa.Machine, 0), err
} else {
defer file.Close()
data, err = ioutil.ReadAll(file)
data, err = io.ReadAll(file)
if err != nil {
return make([]gopenqa.Machine, 0), err
}
Expand Down Expand Up @@ -192,17 +192,17 @@ func readProducts(filename string) ([]gopenqa.Product, error) {
var err error

if filename == "" {
data, err = ioutil.ReadAll(os.Stdin)
data, err = io.ReadAll(os.Stdin)
if err != nil {
return make([]gopenqa.Product, 0), err
}
} else {
// TODO: Don't use ioutil.ReadAll
// TODO: Don't use io.ReadAll
if file, err := os.Open(filename); err != nil {
return make([]gopenqa.Product, 0), err
} else {
defer file.Close()
data, err = ioutil.ReadAll(file)
data, err = io.ReadAll(file)
if err != nil {
return make([]gopenqa.Product, 0), err
}
Expand Down Expand Up @@ -233,17 +233,17 @@ func readJobGroups(filename string) ([]gopenqa.JobGroup, error) {
var err error

if filename == "" {
data, err = ioutil.ReadAll(os.Stdin)
data, err = io.ReadAll(os.Stdin)
if err != nil {
return make([]gopenqa.JobGroup, 0), err
}
} else {
// TODO: Don't use ioutil.ReadAll
// TODO: Don't use io.ReadAll
if file, err := os.Open(filename); err != nil {
return make([]gopenqa.JobGroup, 0), err
} else {
defer file.Close()
data, err = ioutil.ReadAll(file)
data, err = io.ReadAll(file)
if err != nil {
return make([]gopenqa.JobGroup, 0), err
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/grisu48/gopenqa

go 1.14
go 1.16

require (
github.com/google/go-cmp v0.6.0 // indirect
Expand Down
6 changes: 3 additions & 3 deletions gopenqa.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"crypto/sha1"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"net/url"
"os"
Expand Down Expand Up @@ -294,9 +294,9 @@ func (i *Instance) request(method string, url string, data []byte) ([]byte, erro
return make([]byte, 0), err
}

// First read body
// First read body to have it ready in case of errors
defer r.Body.Close()
buf, err := ioutil.ReadAll(r.Body) // TODO: Limit read size
buf, err := io.ReadAll(r.Body) // TODO: Limit read size
if err != nil {
return buf, err
}
Expand Down

0 comments on commit d24ff1f

Please sign in to comment.