Skip to content

Commit

Permalink
fix: Migrate from io/ioutil to io package
Browse files Browse the repository at this point in the history
  • Loading branch information
etu committed Mar 16, 2024
1 parent 7762780 commit 800b7d0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
16 changes: 8 additions & 8 deletions cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"log"
"net/http"
"os"
Expand Down Expand Up @@ -41,7 +41,7 @@ func (cli *Cli) List() {

// Read the body content
defer res.Body.Close()
body, _ := ioutil.ReadAll(res.Body)
body, _ := io.ReadAll(res.Body)

// Parse the json
json.Unmarshal(body, &config)
Expand All @@ -65,7 +65,7 @@ func (cli *Cli) List() {

// Read the body content
defer runnerRes.Body.Close()
runnerBody, _ := ioutil.ReadAll(runnerRes.Body)
runnerBody, _ := io.ReadAll(runnerRes.Body)

// Parse the json
json.Unmarshal(runnerBody, &runners)
Expand Down Expand Up @@ -129,7 +129,7 @@ func (cli *Cli) Add(command string) {
log.Println("Created")
} else {
var response map[string]string
resbody, _ := ioutil.ReadAll(res.Body)
resbody, _ := io.ReadAll(res.Body)

// Parse the json
json.Unmarshal(resbody, &response)
Expand Down Expand Up @@ -167,7 +167,7 @@ func (cli *Cli) Remove(name string) {

// Handle error
var response map[string]string
resbody, _ := ioutil.ReadAll(res.Body)
resbody, _ := io.ReadAll(res.Body)

// Parse the json
json.Unmarshal(resbody, &response)
Expand Down Expand Up @@ -195,7 +195,7 @@ func (cli *Cli) Start(name string) {
log.Println("Started")
} else {
var response map[string]string
resbody, _ := ioutil.ReadAll(res.Body)
resbody, _ := io.ReadAll(res.Body)

// Parse the json
json.Unmarshal(resbody, &response)
Expand Down Expand Up @@ -233,7 +233,7 @@ func (cli *Cli) Stop(name string) {

// Handle error
var response map[string]string
resbody, _ := ioutil.ReadAll(res.Body)
resbody, _ := io.ReadAll(res.Body)

// Parse the json
json.Unmarshal(resbody, &response)
Expand Down Expand Up @@ -268,7 +268,7 @@ func (cli *Cli) Logs(name string) {

// Read the body content
defer runnerRes.Body.Close()
runnerBody, _ := ioutil.ReadAll(runnerRes.Body)
runnerBody, _ := io.ReadAll(runnerRes.Body)

// Parse the json
json.Unmarshal(runnerBody, &runners)
Expand Down
5 changes: 2 additions & 3 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main // import "github.com/etu/goprocmgr"
import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"os"
)
Expand Down Expand Up @@ -44,7 +43,7 @@ func (config *Config) Read(configFileName string) {

if _, err := os.Stat(config.configFileName); err == nil {
// Read the config file
fileContent, err := ioutil.ReadFile(config.configFileName)
fileContent, err := os.ReadFile(config.configFileName)

if err != nil {
log.Fatalf("File read error: %v", err)
Expand All @@ -63,7 +62,7 @@ func (config *Config) Save() {
log.Printf("Writing configuration file at %s\n", config.configFileName)

encodedFile, _ := json.MarshalIndent(config, "", " ")
_ = ioutil.WriteFile(config.configFileName, encodedFile, 0640)
_ = os.WriteFile(config.configFileName, encodedFile, 0640)
}

func (config *Config) WriteServer(server ServerConfig) error {
Expand Down

0 comments on commit 800b7d0

Please sign in to comment.