From 83745a6cc3d1572a43c6c7fe33b19b3017f0188e Mon Sep 17 00:00:00 2001 From: xgfone Date: Thu, 12 Oct 2023 22:09:44 +0800 Subject: [PATCH] replace the deprecated std package --- snapshot.go | 20 +++++++++----------- source_url.go | 4 ++-- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/snapshot.go b/snapshot.go index 53fe4de..726cb7d 100644 --- a/snapshot.go +++ b/snapshot.go @@ -16,7 +16,6 @@ package gconf import ( "encoding/json" - "io/ioutil" "os" "sync/atomic" "time" @@ -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) @@ -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 @@ -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)) diff --git a/source_url.go b/source_url.go index ca722a5..4939b86 100644 --- a/source_url.go +++ b/source_url.go @@ -16,7 +16,7 @@ package gconf import ( "fmt" - "io/ioutil" + "io" "net/http" neturl "net/url" "strings" @@ -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 }