Skip to content

Commit

Permalink
Remove ioutil for io and os
Browse files Browse the repository at this point in the history
ioutil is deprecated and these methods are available in other
packages now.

Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alexellis2@gmail.com>
  • Loading branch information
alexellis committed Jun 6, 2023
1 parent 5190205 commit 6406ee9
Show file tree
Hide file tree
Showing 24 changed files with 59 additions and 61 deletions.
2 changes: 1 addition & 1 deletion builder/publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ func callBuilder(tarPath, tempPath, builderAddress, functionName, payloadSecretP
}
defer tarFile.Close()

tarFileBytes, err := ioutil.ReadAll(tarFile)
tarFileBytes, err := io.ReadAll(tarFile)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions commands/invoke.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package commands
import (
"encoding/hex"
"fmt"
"io/ioutil"
"io"
"os"

"github.com/alexellis/hmac"
Expand Down Expand Up @@ -95,7 +95,7 @@ func runInvoke(cmd *cobra.Command, args []string) error {
fmt.Fprintf(os.Stderr, "Reading from STDIN - hit (Control + D) to stop.\n")
}

functionInput, err := ioutil.ReadAll(os.Stdin)
functionInput, err := io.ReadAll(os.Stdin)
if err != nil {
return fmt.Errorf("unable to read standard input: %s", err.Error())
}
Expand Down
6 changes: 3 additions & 3 deletions commands/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ package commands

import (
"fmt"
"io/ioutil"
"io"
"net/http"
"os"
"strings"
Expand Down Expand Up @@ -71,7 +71,7 @@ func runLogin(cmd *cobra.Command, args []string) error {
return fmt.Errorf("must provide --username with --password-stdin")
}

passwordStdin, err := ioutil.ReadAll(os.Stdin)
passwordStdin, err := io.ReadAll(os.Stdin)
if err != nil {
return err
}
Expand Down Expand Up @@ -144,7 +144,7 @@ func validateLogin(gatewayURL string, user string, pass string, timeout time.Dur
case http.StatusUnauthorized:
return fmt.Errorf("unable to login, either username or password is incorrect")
default:
bytesOut, err := ioutil.ReadAll(res.Body)
bytesOut, err := io.ReadAll(res.Body)
if err == nil {
return fmt.Errorf("server returned unexpected status code: %d - %s", res.StatusCode, string(bytesOut))
}
Expand Down
2 changes: 1 addition & 1 deletion commands/new_function.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ func printAvailableTemplates(availableTemplates []string) string {
}

func duplicateFunctionName(functionName string, appendFile string) error {
fileBytes, readErr := ioutil.ReadFile(appendFile)
fileBytes, readErr := os.ReadFile(appendFile)
if readErr != nil {
return fmt.Errorf("unable to read %s to append, %s", appendFile, readErr)
}
Expand Down
3 changes: 2 additions & 1 deletion commands/registry_login.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"encoding/base64"
"encoding/json"
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
Expand Down Expand Up @@ -101,7 +102,7 @@ func generateRegistryAuthFile(command *cobra.Command, _ []string) error {

} else if passStdin {
fmt.Printf("Enter your password, hit enter then type Ctrl+D\n\nPassword: ")
passwordStdin, err := ioutil.ReadAll(os.Stdin)
passwordStdin, err := io.ReadAll(os.Stdin)
if err != nil {
return err
}
Expand Down
6 changes: 3 additions & 3 deletions commands/secret_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package commands
import (
"context"
"fmt"
"io/ioutil"
"io"
"os"
"regexp"
"strings"
Expand Down Expand Up @@ -84,7 +84,7 @@ func runSecretCreate(cmd *cobra.Command, args []string) error {
secret.Value = literalSecret

case len(secretFile) > 0:
fileData, err := ioutil.ReadFile(secretFile)
fileData, err := os.ReadFile(secretFile)
if err != nil {
return err
}
Expand All @@ -99,7 +99,7 @@ func runSecretCreate(cmd *cobra.Command, args []string) error {
fmt.Fprintf(os.Stderr, "Reading from STDIN - hit (Control + D) to stop.\n")
}

secretStdin, err := ioutil.ReadAll(os.Stdin)
secretStdin, err := io.ReadAll(os.Stdin)
if err != nil {
return err
}
Expand Down
6 changes: 3 additions & 3 deletions commands/secret_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package commands
import (
"context"
"fmt"
"io/ioutil"
"io"
"os"
"strings"

Expand Down Expand Up @@ -74,7 +74,7 @@ func runSecretUpdate(cmd *cobra.Command, args []string) error {
secret.Value = literalSecret

case len(secretFile) > 0:
content, err := ioutil.ReadFile(secretFile)
content, err := os.ReadFile(secretFile)
if err != nil {
return fmt.Errorf("unable to read secret file: %s", err.Error())
}
Expand All @@ -86,7 +86,7 @@ func runSecretUpdate(cmd *cobra.Command, args []string) error {
fmt.Fprintf(os.Stderr, "Reading from STDIN - hit (Control + D) to stop.\n")
}

secretStdin, err := ioutil.ReadAll(os.Stdin)
secretStdin, err := io.ReadAll(os.Stdin)
if err != nil {
return fmt.Errorf("unable to read standard input: %s", err.Error())
}
Expand Down
6 changes: 3 additions & 3 deletions commands/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package commands
import (
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"strings"
"time"
Expand Down Expand Up @@ -73,7 +73,7 @@ func storeList(store string) ([]storeV2.StoreFunction, error) {

switch res.StatusCode {
case http.StatusOK:
bytesOut, err := ioutil.ReadAll(res.Body)
bytesOut, err := io.ReadAll(res.Body)
if err != nil {
return nil, fmt.Errorf("cannot read result from OpenFaaS store at URL: %s", store)
}
Expand All @@ -83,7 +83,7 @@ func storeList(store string) ([]storeV2.StoreFunction, error) {
return nil, fmt.Errorf("cannot parse result from OpenFaaS store at URL: %s\n%s", store, jsonErr.Error())
}
default:
bytesOut, err := ioutil.ReadAll(res.Body)
bytesOut, err := io.ReadAll(res.Body)
if err == nil {
return nil, fmt.Errorf("server returned unexpected status code: %d - %s", res.StatusCode, string(bytesOut))
}
Expand Down
3 changes: 1 addition & 2 deletions commands/template_pull_stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package commands

import (
"fmt"
"io/ioutil"
"os"

"gopkg.in/yaml.v3"
Expand Down Expand Up @@ -55,7 +54,7 @@ func loadTemplateConfig() ([]stack.TemplateSource, error) {
func readStackConfig() (stack.Configuration, error) {
configField := stack.Configuration{}

configFieldBytes, err := ioutil.ReadFile(yamlFile)
configFieldBytes, err := os.ReadFile(yamlFile)
if err != nil {
return configField, fmt.Errorf("can't read file %s, error: %s", yamlFile, err.Error())
}
Expand Down
3 changes: 1 addition & 2 deletions commands/update_gitignore.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package commands

import (
"io/ioutil"
"os"
"strings"
)
Expand Down Expand Up @@ -43,7 +42,7 @@ func updateGitignore() (err error) {

defer f.Close()

content, err := ioutil.ReadFile(".gitignore")
content, err := os.ReadFile(".gitignore")
if err != nil {
return err
}
Expand Down
3 changes: 1 addition & 2 deletions config/config_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"encoding/base64"

"fmt"
"io/ioutil"
"net/url"
"os"
"path"
Expand Down Expand Up @@ -179,7 +178,7 @@ func (configFile *ConfigFile) load() error {
return fmt.Errorf("can't load config from non existent filePath")
}

data, err := ioutil.ReadFile(configFile.FilePath)
data, err := os.ReadFile(configFile.FilePath)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions proxy/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"net/url"

Expand Down Expand Up @@ -54,7 +54,7 @@ func (c *Client) DeleteFunction(ctx context.Context, functionName string, namesp
err = fmt.Errorf("unauthorized access, run \"faas-cli login\" to setup authentication for this server")
default:
var bodyReadErr error
bytesOut, bodyReadErr := ioutil.ReadAll(res.Body)
bytesOut, bodyReadErr := io.ReadAll(res.Body)
if bodyReadErr != nil {
err = bodyReadErr
} else {
Expand Down
4 changes: 2 additions & 2 deletions proxy/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"net/url"
"time"
Expand Down Expand Up @@ -175,7 +175,7 @@ func (c *Client) deploy(context context.Context, spec *DeployFunctionSpec, updat
deployOutput += fmt.Sprintln("unauthorized access, run \"faas-cli login\" to setup authentication for this server")

default:
bytesOut, err := ioutil.ReadAll(res.Body)
bytesOut, err := io.ReadAll(res.Body)
if err == nil {
deployOutput += fmt.Sprintf("Unexpected status: %d, message: %s\n", res.StatusCode, string(bytesOut))
}
Expand Down
6 changes: 3 additions & 3 deletions proxy/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"net/url"
"path"
Expand Down Expand Up @@ -48,7 +48,7 @@ func (c *Client) GetFunctionInfo(ctx context.Context, functionName string, names

switch res.StatusCode {
case http.StatusOK:
bytesOut, err := ioutil.ReadAll(res.Body)
bytesOut, err := io.ReadAll(res.Body)
if err != nil {
return result, fmt.Errorf("cannot read result from OpenFaaS on URL: %s", c.GatewayURL.String())
}
Expand All @@ -63,7 +63,7 @@ func (c *Client) GetFunctionInfo(ctx context.Context, functionName string, names
case http.StatusNotFound:
return result, fmt.Errorf("no such function: %s", functionName)
default:
bytesOut, err := ioutil.ReadAll(res.Body)
bytesOut, err := io.ReadAll(res.Body)
if err == nil {
return result, fmt.Errorf("server returned unexpected status code: %d - %s", res.StatusCode, string(bytesOut))
}
Expand Down
9 changes: 5 additions & 4 deletions proxy/function_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ package proxy
import (
"encoding/json"
"fmt"
v2 "github.com/openfaas/faas-cli/schema/store/v2"
"io/ioutil"
"io"
"net/http"
"strings"
"time"

v2 "github.com/openfaas/faas-cli/schema/store/v2"
)

type StoreResult struct {
Expand Down Expand Up @@ -38,7 +39,7 @@ func FunctionStoreList(store string) ([]v2.StoreFunction, error) {

switch res.StatusCode {
case http.StatusOK:
bytesOut, err := ioutil.ReadAll(res.Body)
bytesOut, err := io.ReadAll(res.Body)
if err != nil {
return nil, fmt.Errorf("cannot read result from OpenFaaS store at URL: %s", store)
}
Expand All @@ -48,7 +49,7 @@ func FunctionStoreList(store string) ([]v2.StoreFunction, error) {
return nil, fmt.Errorf("cannot parse result from OpenFaaS store at URL: %s\n%s", store, jsonErr.Error())
}
default:
bytesOut, err := ioutil.ReadAll(res.Body)
bytesOut, err := io.ReadAll(res.Body)
if err == nil {
return nil, fmt.Errorf("server returned unexpected status code: %d - %s", res.StatusCode, string(bytesOut))
}
Expand Down
6 changes: 3 additions & 3 deletions proxy/invoke.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ package proxy

import (
"bytes"
"io"
"os"

"fmt"
"io/ioutil"
"net/http"
"strings"
"time"
Expand Down Expand Up @@ -85,14 +85,14 @@ func InvokeFunction(gateway string, name string, bytesIn *[]byte, contentType st
fmt.Fprintf(os.Stderr, "Function submitted asynchronously.\n")
case http.StatusOK:
var readErr error
resBytes, readErr = ioutil.ReadAll(res.Body)
resBytes, readErr = io.ReadAll(res.Body)
if readErr != nil {
return nil, fmt.Errorf("cannot read result from OpenFaaS on URL: %s %s", gateway, readErr)
}
case http.StatusUnauthorized:
return nil, fmt.Errorf("unauthorized access, run \"faas-cli login\" to setup authentication for this server")
default:
bytesOut, err := ioutil.ReadAll(res.Body)
bytesOut, err := io.ReadAll(res.Body)
if err == nil {
return nil, fmt.Errorf("server returned unexpected status code: %d - %s", res.StatusCode, string(bytesOut))
}
Expand Down
6 changes: 3 additions & 3 deletions proxy/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ package proxy
import (
"context"
"encoding/json"
"io"

"fmt"
"io/ioutil"
"net/http"
"net/url"

Expand Down Expand Up @@ -50,7 +50,7 @@ func (c *Client) ListFunctions(ctx context.Context, namespace string) ([]types.F
switch res.StatusCode {
case http.StatusOK:

bytesOut, err := ioutil.ReadAll(res.Body)
bytesOut, err := io.ReadAll(res.Body)
if err != nil {
return nil, fmt.Errorf("cannot read result from OpenFaaS on URL: %s", c.GatewayURL.String())
}
Expand All @@ -61,7 +61,7 @@ func (c *Client) ListFunctions(ctx context.Context, namespace string) ([]types.F
case http.StatusUnauthorized:
return nil, fmt.Errorf("unauthorized access, run \"faas-cli login\" to setup authentication for this server")
default:
bytesOut, err := ioutil.ReadAll(res.Body)
bytesOut, err := io.ReadAll(res.Body)
if err == nil {
return nil, fmt.Errorf("server returned unexpected status code: %d - %s", res.StatusCode, string(bytesOut))
}
Expand Down
4 changes: 2 additions & 2 deletions proxy/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"crypto/tls"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"log"
"net/http"
"net/url"
Expand Down Expand Up @@ -56,7 +56,7 @@ func (c *Client) GetLogs(ctx context.Context, params logs.Request) (<-chan logs.
case http.StatusUnauthorized:
return nil, fmt.Errorf("unauthorized access, run \"faas-cli login\" to setup authentication for this server")
default:
bytesOut, err := ioutil.ReadAll(res.Body)
bytesOut, err := io.ReadAll(res.Body)
if err == nil {
return nil, fmt.Errorf("server returned unexpected status code: %d - %s", res.StatusCode, string(bytesOut))
}
Expand Down
Loading

0 comments on commit 6406ee9

Please sign in to comment.