diff --git a/config.go b/config.go index 50eeddd..7e6b96a 100644 --- a/config.go +++ b/config.go @@ -2,7 +2,6 @@ package main import ( "bufio" - "io/ioutil" "os" "path/filepath" "reflect" @@ -21,7 +20,7 @@ var ( // readConfigfile creates the ConfigSettings struct from the g10k config file func readConfigfile(configFile string) ConfigSettings { Debugf("Trying to read g10k config file: " + configFile) - data, err := ioutil.ReadFile(configFile) + data, err := os.ReadFile(configFile) if err != nil { Fatalf("readConfigfile(): There was an error parsing the config file " + configFile + ": " + err.Error()) } diff --git a/forge.go b/forge.go index ca0db63..554ef60 100644 --- a/forge.go +++ b/forge.go @@ -6,7 +6,6 @@ import ( "encoding/hex" "fmt" "io" - "io/ioutil" "net/http" "os" "path/filepath" @@ -32,7 +31,7 @@ func checkDeprecation(fm ForgeModule, lastCheckedFile string) bool { } else if fm.cacheTTL > 0 && fileInfo.ModTime().Add(fm.cacheTTL).Before(time.Now()) { return false } else { - json, err := ioutil.ReadFile(lastCheckedFile) + json, err := os.ReadFile(lastCheckedFile) if err != nil { Fatalf("doModuleInstallOrNothing(): Error while reading Forge API result from file " + lastCheckedFile + err.Error()) } @@ -202,7 +201,7 @@ func queryForgeAPI(fm ForgeModule) ForgeResult { if resp.StatusCode == http.StatusOK { // need to get latest version - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) if err != nil { Fatalf("queryForgeAPI(): Error while reading response body for Forge module " + fm.name + " from " + url + ": " + err.Error()) } @@ -306,7 +305,7 @@ func getMetadataForgeModule(fm ForgeModule) ForgeModule { defer resp.Body.Close() if resp.StatusCode == http.StatusOK { - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) if err != nil { Fatalf("getMetadataForgeModule(): Error while reading response body for Forge module " + fm.name + " from " + url + ": " + err.Error()) @@ -454,7 +453,7 @@ func downloadForgeModule(name string, version string, fm ForgeModule, retryCount // readModuleMetadata returns the Forgemodule struct of the given module file path func readModuleMetadata(file string) ForgeModule { - content, _ := ioutil.ReadFile(file) + content, _ := os.ReadFile(file) before := time.Now() name := gjson.Get(string(content), "name").String() diff --git a/g10k_test.go b/g10k_test.go index d4b6206..18ea1d7 100755 --- a/g10k_test.go +++ b/g10k_test.go @@ -2,7 +2,6 @@ package main import ( "fmt" - "io/ioutil" "net/http" "net/http/httptest" "os" @@ -560,19 +559,19 @@ func spinUpFakeForge(t *testing.T, metadataFile string) *httptest.Server { // spin up HTTP test server to serve fake/invalid Forge module metadata ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { if r.URL.Path == "/v3/releases/puppetlabs-ntp-6.0.0" { - body, err := ioutil.ReadFile(metadataFile) + body, err := os.ReadFile(metadataFile) if err != nil { t.Error(err) } fmt.Fprint(w, string(body)) } else if r.URL.Path == "/v3/modules/puppetlabs-ntp" { - body, err := ioutil.ReadFile("tests/fake-forge/latest-puppetlabs-ntp-metadata.json") + body, err := os.ReadFile("tests/fake-forge/latest-puppetlabs-ntp-metadata.json") if err != nil { t.Error(err) } fmt.Fprint(w, string(body)) } else if r.URL.Path == "/v3/files/puppetlabs-ntp-6.0.0.tar.gz" { - body, err := ioutil.ReadFile("tests/fake-forge/fake-puppetlabs-ntp-6.0.0.tar.gz") + body, err := os.ReadFile("tests/fake-forge/fake-puppetlabs-ntp-6.0.0.tar.gz") if err != nil { t.Error(err) } @@ -1753,7 +1752,7 @@ func TestLastCheckedFile(t *testing.T) { } fm := ForgeModule{version: "latest", name: "inifile", author: "puppetlabs", fileSize: 0, cacheTTL: 0} - json, _ := ioutil.ReadFile(lastCheckedFile) + json, _ := os.ReadFile(lastCheckedFile) latestForgeModules.m = make(map[string]string) result := parseForgeAPIResult(string(json), fm) @@ -1779,7 +1778,7 @@ func TestLastCheckedFile(t *testing.T) { branchParam = "single_cache" resolvePuppetEnvironment(false, "") - json, _ = ioutil.ReadFile(lastCheckedFile) + json, _ = os.ReadFile(lastCheckedFile) result = parseForgeAPIResult(string(json), fm) result2 = queryForgeAPI(fm) @@ -1860,7 +1859,7 @@ func TestPostrunCommand(t *testing.T) { t.Errorf("postrun logfile file missing: %s", postrunLogfile) } - content, _ := ioutil.ReadFile(postrunLogfile) + content, _ := os.ReadFile(postrunLogfile) expectedLines := []string{ "postrun command wrapper script received argument: example_master", @@ -1909,7 +1908,7 @@ func TestPostrunCommandDirs(t *testing.T) { t.Errorf("postrun logfile file missing: %s", postrunLogfile) } - content, _ := ioutil.ReadFile(postrunLogfile) + content, _ := os.ReadFile(postrunLogfile) expectedLines := []string{ "postrun command wrapper script received argument: /tmp/example/example_master", @@ -2681,7 +2680,7 @@ func TestCloneGitModules(t *testing.T) { // check for _, expectedDir := range expectedDirs { headFile := filepath.Join(expectedDir, "HEAD") - content, err := ioutil.ReadFile(headFile) + content, err := os.ReadFile(headFile) if err != nil { t.Errorf("Error while reading content of file " + headFile + " Error: " + err.Error()) } diff --git a/git.go b/git.go index 72a5c5c..356d417 100644 --- a/git.go +++ b/git.go @@ -2,7 +2,6 @@ package main import ( "fmt" - "io/ioutil" "os" "os/exec" "path/filepath" @@ -208,7 +207,7 @@ func syncToModuleDir(gitModule GitModule, srcDir string, targetDir string, corre } } } else { - targetHashByte, _ := ioutil.ReadFile(hashFile) + targetHashByte, _ := os.ReadFile(hashFile) targetHash := string(targetHashByte) Debugf("string content of " + hashFile + " is: " + targetHash) if targetHash == commitHash { diff --git a/helper.go b/helper.go index 56732eb..f56ea75 100644 --- a/helper.go +++ b/helper.go @@ -6,7 +6,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "log" "os" "os/exec" @@ -315,7 +314,7 @@ func writeStructJSONFile(file string, v interface{}) { Warnf("Could not encode JSON file " + file + " " + err.Error()) } - err = ioutil.WriteFile(file, content, 0644) + err = os.WriteFile(file, content, 0644) if err != nil { Warnf("Could not write JSON file " + file + " " + err.Error()) } @@ -331,7 +330,7 @@ func readDeployResultFile(file string) DeployResult { } defer jsonFile.Close() - byteValue, err := ioutil.ReadAll(jsonFile) + byteValue, err := io.ReadAll(jsonFile) if err != nil { Warnf("Could not read JSON file " + file + " " + err.Error()) }