Skip to content

Commit

Permalink
chore: ioutil is DEPRECATED
Browse files Browse the repository at this point in the history
  • Loading branch information
fliiiix committed Aug 26, 2022
1 parent 5610670 commit af45e5b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
8 changes: 4 additions & 4 deletions pkg/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"archive/zip"
"fmt"
"io"
"io/ioutil"
"log"
"os"
"path/filepath"

util "github.com/docat-org/docatl/internal"
Expand All @@ -29,7 +29,7 @@ func Build(docsPath string, meta BuildMetadata) (string, error) {
docsPath = util.ResolvePath(docsPath)

// NOTE(TF): the `archiver` package does not have an option to not create a top-level directory
filesInDocsPath, err := ioutil.ReadDir(docsPath)
filesInDocsPath, err := os.ReadDir(docsPath)
if err != nil {
return "", fmt.Errorf("cannot list the contents within the given documentation directory: %w", err)
}
Expand Down Expand Up @@ -70,7 +70,7 @@ func generateArtifactFileName(docsPath string, meta BuildMetadata) string {
}

func generateMetadataFile(meta BuildMetadata) (string, error) {
tmpDir, err := ioutil.TempDir("", "docatl-*")
tmpDir, err := os.MkdirTemp("", "docatl-*")
if err != nil {
return "", fmt.Errorf("unable to create temp directory for metadatafile: %w", err)
}
Expand All @@ -81,7 +81,7 @@ func generateMetadataFile(meta BuildMetadata) (string, error) {
return "", fmt.Errorf("unable to generate metadata file for data: %v: %w", meta, err)
}

err = ioutil.WriteFile(metadataFile, doc, 0755)
err = os.WriteFile(metadataFile, doc, 0755)
if err != nil {
return "", fmt.Errorf("unabel to write metadata to file %s: %w", metadataFile, err)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package docatl

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

"gopkg.in/yaml.v3"
)
Expand All @@ -18,7 +18,7 @@ func WriteConfig(configPath string, config Config) error {
return fmt.Errorf("unable to marshal config '%v' to YAML: %w", config, err)
}

err = ioutil.WriteFile(configPath, doc, 0644)
err = os.WriteFile(configPath, doc, 0644)
if err != nil {
return fmt.Errorf("unable to write config to '%s': %w", configPath, err)
}
Expand Down
9 changes: 4 additions & 5 deletions pkg/docat.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"mime/multipart"
"net/http"
"os"
Expand Down Expand Up @@ -58,7 +57,7 @@ func (docat *Docat) Post(project string, version string, docsPath string) error
defer response.Body.Close()

if response.StatusCode != http.StatusCreated {
bodyBytes, err := ioutil.ReadAll(response.Body)
bodyBytes, err := io.ReadAll(response.Body)
if err != nil {
return fmt.Errorf("unable to upload documentation and read it's response (status code: %d", response.StatusCode)
}
Expand All @@ -84,7 +83,7 @@ func (docat *Docat) Delete(project string, version string) error {
defer response.Body.Close()

if response.StatusCode != http.StatusOK {
bodyBytes, err := ioutil.ReadAll(response.Body)
bodyBytes, err := io.ReadAll(response.Body)
if err != nil {
return fmt.Errorf("unable to delete documentation and read it's response (status code: %d", response.StatusCode)
}
Expand All @@ -102,7 +101,7 @@ func (docat *Docat) Claim(project string) (ProjectClaim, error) {
}
defer response.Body.Close()

bodyBytes, err := ioutil.ReadAll(response.Body)
bodyBytes, err := io.ReadAll(response.Body)
if err != nil {
return ProjectClaim{}, fmt.Errorf("unable to claim project and read it's response (status code: %d", response.StatusCode)
}
Expand Down Expand Up @@ -133,7 +132,7 @@ func (docat *Docat) Tag(project string, version string, tag string) error {
defer response.Body.Close()

if response.StatusCode != http.StatusCreated {
bodyBytes, err := ioutil.ReadAll(response.Body)
bodyBytes, err := io.ReadAll(response.Body)
if err != nil {
return fmt.Errorf("unable to tag documentation and read it's response (status code: %d", response.StatusCode)
}
Expand Down

0 comments on commit af45e5b

Please sign in to comment.