Skip to content

Commit

Permalink
replace the deprecated std package
Browse files Browse the repository at this point in the history
  • Loading branch information
xgfone committed Oct 12, 2023
1 parent d8884ba commit 83745a6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
20 changes: 9 additions & 11 deletions snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package gconf

import (
"encoding/json"
"io/ioutil"
"os"
"sync/atomic"
"time"
Expand All @@ -30,7 +29,7 @@ func (c *Config) LoadBackupFile(filename string) (err error) {
panic("the backup filename must not be empty")
}

data, err := ioutil.ReadFile(filename)
data, err := os.ReadFile(filename)
if err != nil {
if !os.IsNotExist(err) {
c.errorf("fail to read the backup file '%s': %s", filename, err)
Expand Down Expand Up @@ -78,7 +77,7 @@ func (c *Config) writeSnapshotIntoFile(filename string) {
continue
}

if err := ioutil.WriteFile(filename, data, os.ModePerm); err != nil {
if err := os.WriteFile(filename, data, os.ModePerm); err != nil {
c.errorf("cannot write snapshot into file '%s': %s", filename, err)
} else {
lastgen = gen
Expand All @@ -92,14 +91,13 @@ func (c *Config) writeSnapshotIntoFile(filename string) {
//
// For example,
//
// map[string]interface{} {
// "opt1": "value1",
// "opt2": "value2",
// "group1.opt3": "value3",
// "group1.group2.opt4": "value4",
// // ...
// }
//
// map[string]interface{} {
// "opt1": "value1",
// "opt2": "value2",
// "group1.opt3": "value3",
// "group1.group2.opt4": "value4",
// // ...
// }
func (c *Config) Snapshot() (generation uint64, snap map[string]interface{}) {
generation = atomic.LoadUint64(&c.gen)
snap = make(map[string]interface{}, len(c.options))
Expand Down
4 changes: 2 additions & 2 deletions source_url.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ package gconf

import (
"fmt"
"io/ioutil"
"io"
"net/http"
neturl "net/url"
"strings"
Expand Down Expand Up @@ -95,7 +95,7 @@ func (u urlSource) Read() (DataSet, error) {
}

// Read the body of the response.
data, err := ioutil.ReadAll(resp.Body)
data, err := io.ReadAll(resp.Body)
if err != nil {
return DataSet{Source: u.id, Format: format}, err
}
Expand Down

0 comments on commit 83745a6

Please sign in to comment.