misc: lint and remove deprecated ioutil method calls

This commit is contained in:
Joel Rebello 2022-11-24 16:16:40 +01:00
parent ed927404da
commit 816e98350c
No known key found for this signature in database
GPG Key ID: EDB938BE882F8078
3 changed files with 13 additions and 28 deletions

View File

@ -6,7 +6,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"mime/multipart"
"net/http"
"net/http/httputil"
@ -105,8 +104,8 @@ type preserveConfig struct {
}
// Firmware flash progress
//{ "id": 1, "action": "Flashing...", "progress": "12% done ", "state": 0 }
//{ "id": 1, "action": "Flashing...", "progress": "100% done", "state": 0 }
// { "id": 1, "action": "Flashing...", "progress": "12% done ", "state": 0 }
// { "id": 1, "action": "Flashing...", "progress": "100% done", "state": 0 }
type upgradeProgress struct {
ID int `json:"id,omitempty"`
Action string `json:"action,omitempty"`
@ -463,12 +462,7 @@ func (a *ASRockRack) biosUpgradeConfiguration(ctx context.Context) error {
}
f := &firmwareInfo{}
err = json.Unmarshal(resp, f)
if err != nil {
return err
}
return nil
return json.Unmarshal(resp, f)
}
// Run BIOS upgrade
@ -493,12 +487,7 @@ func (a *ASRockRack) upgradeBIOS(ctx context.Context) error {
}
f := &firmwareInfo{}
err = json.Unmarshal(resp, f)
if err != nil {
return err
}
return nil
return json.Unmarshal(resp, f)
}
// Returns the chassis status object which includes the power state
@ -560,13 +549,10 @@ func (a *ASRockRack) httpsLogout(ctx context.Context) error {
return fmt.Errorf("Error logging out: " + err.Error())
}
if err != nil {
return fmt.Errorf("Error logging out: " + err.Error())
}
if statusCode != http.StatusOK {
return fmt.Errorf("non 200 response at https logout: %d", statusCode)
}
return nil
}
@ -614,7 +600,7 @@ func (a *ASRockRack) queryHTTPS(ctx context.Context, endpoint, method string, pa
a.log.V(3).Info("trace", "responseDump", string(respDump))
}
body, err = ioutil.ReadAll(resp.Body)
body, err = io.ReadAll(resp.Body)
if err != nil {
return body, 0, err
}

View File

@ -3,7 +3,7 @@ package asrockrack
import (
"bytes"
"encoding/json"
"io/ioutil"
"io"
"log"
"net/http"
"net/http/httptest"
@ -71,7 +71,7 @@ func TestMain(m *testing.M) {
os.Exit(m.Run())
}
/////////////// mock bmc service ///////////////////////////
// ///////////// mock bmc service ///////////////////////////
func mockASRockBMC() *httptest.Server {
handler := http.NewServeMux()
handler.HandleFunc("/", index)
@ -270,7 +270,7 @@ func sensorsinfo(w http.ResponseWriter, r *http.Request) {
log.Fatal(err)
}
b, err := ioutil.ReadAll(fh)
b, err := io.ReadAll(fh)
if err != nil {
log.Fatal(err)
}
@ -296,7 +296,7 @@ func session(w http.ResponseWriter, r *http.Request) {
switch r.Method {
case "POST":
// login to BMC
b, _ := ioutil.ReadAll(r.Body)
b, _ := io.ReadAll(r.Body)
if string(b) == string(loginPayload) {
// login request needs to be of the right content-typ
if r.Header.Get("Content-Type") != "application/x-www-form-urlencoded" {

View File

@ -3,7 +3,6 @@ package ipmitool
import (
"context"
"fmt"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
@ -17,7 +16,7 @@ func TestMain(m *testing.M) {
var tempDir string
_, err := exec.LookPath("ipmitool")
if err != nil {
tempDir, err = ioutil.TempDir("/tmp", "")
tempDir, err = os.MkdirTemp("/tmp", "")
if err != nil {
os.Exit(2)
}
@ -25,7 +24,7 @@ func TestMain(m *testing.M) {
os.Setenv("PATH", path)
fmt.Println(os.Getenv("PATH"))
f := filepath.Join(tempDir, "ipmitool")
err = ioutil.WriteFile(f, []byte{}, 0755)
err = os.WriteFile(f, []byte{}, 0755)
if err != nil {
os.RemoveAll(tempDir)
os.Exit(3)