diff options
| author | Shulhan <ms@kilabit.info> | 2022-04-06 01:40:07 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2022-04-06 02:37:22 +0700 |
| commit | 429a9d9205bad2be34cdfe7fb5b1a9a6f127f541 (patch) | |
| tree | 1debf749d60e00a5ac03a3fecc6960aead0ad236 | |
| parent | 7186de3415b130a6c67388d8f1bcf54404f6202b (diff) | |
| download | pakakeh.go-429a9d9205bad2be34cdfe7fb5b1a9a6f127f541.tar.xz | |
all: replace any usage of ioutil package with os or io
Since Go 1.16, the ioutil package has been deprecated.
This changes replace any usage that use functions from ioutil package
with their replacement from package os or package io.
50 files changed, 100 insertions, 123 deletions
diff --git a/api/slack/slack.go b/api/slack/slack.go index 360a43db..c5546c61 100644 --- a/api/slack/slack.go +++ b/api/slack/slack.go @@ -12,7 +12,7 @@ import ( "bytes" "encoding/json" "fmt" - "io/ioutil" + "io" "net/http" ) @@ -32,7 +32,7 @@ func PostWebhook(webhookUrl string, msg *Message) (err error) { } if res.StatusCode != http.StatusOK { - resBody, err := ioutil.ReadAll(res.Body) + resBody, err := io.ReadAll(res.Body) if err != nil { return fmt.Errorf("PostWebhook: %w", err) } diff --git a/cmd/cart/main.go b/cmd/cart/main.go index dc2a9c38..c4f10bfc 100644 --- a/cmd/cart/main.go +++ b/cmd/cart/main.go @@ -8,7 +8,6 @@ import ( "encoding/json" "flag" "fmt" - "io/ioutil" "os" "time" @@ -54,7 +53,7 @@ func un(s string, startTime time.Time) { func createCart(fcfg string, opts *options) (*cart.Runtime, error) { cartrt := &cart.Runtime{} - config, e := ioutil.ReadFile(fcfg) + config, e := os.ReadFile(fcfg) if e != nil { return nil, e } diff --git a/cmd/cascaded-random-forest/main.go b/cmd/cascaded-random-forest/main.go index b6270be9..e3765e1f 100644 --- a/cmd/cascaded-random-forest/main.go +++ b/cmd/cascaded-random-forest/main.go @@ -8,7 +8,6 @@ import ( "encoding/json" "flag" "fmt" - "io/ioutil" "os" "time" @@ -92,7 +91,7 @@ func un(startTime time.Time) { // func createCRF(o *options) (crforest *crf.Runtime, e error) { // (1) - config, e := ioutil.ReadFile(o.trainCfg) + config, e := os.ReadFile(o.trainCfg) if e != nil { return nil, e } diff --git a/cmd/gofmtcomment/main.go b/cmd/gofmtcomment/main.go index 0511a8b1..443edcd6 100644 --- a/cmd/gofmtcomment/main.go +++ b/cmd/gofmtcomment/main.go @@ -9,7 +9,7 @@ package main import ( "fmt" - "io/ioutil" + "io" "log" "os" "regexp" @@ -41,7 +41,7 @@ func main() { log.Fatal(err) } - in, err := ioutil.ReadAll(f) + in, err := io.ReadAll(f) if err != nil { log.Fatal(err) } diff --git a/cmd/lnsmote/main.go b/cmd/lnsmote/main.go index 034b5911..f6cf07fd 100644 --- a/cmd/lnsmote/main.go +++ b/cmd/lnsmote/main.go @@ -8,7 +8,6 @@ import ( "encoding/json" "flag" "fmt" - "io/ioutil" "os" "time" @@ -81,7 +80,7 @@ func un(s string, startTime time.Time) { func createLnsmote(fcfg string, opts *options) (lnsmoteRun *lnsmote.Runtime, e error) { lnsmoteRun = &lnsmote.Runtime{} - config, e := ioutil.ReadFile(fcfg) + config, e := os.ReadFile(fcfg) if e != nil { return nil, e } diff --git a/cmd/random-forest/main.go b/cmd/random-forest/main.go index cf43f34b..df84f33e 100644 --- a/cmd/random-forest/main.go +++ b/cmd/random-forest/main.go @@ -8,7 +8,6 @@ import ( "encoding/json" "flag" "fmt" - "io/ioutil" "os" "time" @@ -88,7 +87,7 @@ func un(startTime time.Time) { // func createRandomForest(opts *options) (forest *rf.Runtime, e error) { // (1) - config, e := ioutil.ReadFile(opts.trainCfg) + config, e := os.ReadFile(opts.trainCfg) if e != nil { return nil, e } diff --git a/cmd/smote/main.go b/cmd/smote/main.go index 023ef090..0e4d6613 100644 --- a/cmd/smote/main.go +++ b/cmd/smote/main.go @@ -8,7 +8,6 @@ import ( "encoding/json" "flag" "fmt" - "io/ioutil" "os" "time" @@ -79,7 +78,7 @@ func un(s string, startTime time.Time) { func createSmote(fcfg string, o *options) (smoteRun *smote.Runtime, e error) { smoteRun = &smote.Runtime{} - config, e := ioutil.ReadFile(fcfg) + config, e := os.ReadFile(fcfg) if e != nil { return nil, e } diff --git a/cmd/smtpcli/client.go b/cmd/smtpcli/client.go index 3281362e..cdcf5e1d 100644 --- a/cmd/smtpcli/client.go +++ b/cmd/smtpcli/client.go @@ -7,7 +7,6 @@ package main import ( "bytes" "fmt" - "io/ioutil" "log" "os" "strings" @@ -138,7 +137,7 @@ func (cli *client) handleInput() (isQuit bool) { } func (cli *client) readData(fin string) (err error) { - cli.mailTx.Data, err = ioutil.ReadFile(fin) + cli.mailTx.Data, err = os.ReadFile(fin) if err != nil { return err } diff --git a/lib/contact/google/contact_test.go b/lib/contact/google/contact_test.go index 2e518f45..873de413 100644 --- a/lib/contact/google/contact_test.go +++ b/lib/contact/google/contact_test.go @@ -6,7 +6,7 @@ package google import ( "encoding/json" - "io/ioutil" + "os" "testing" "github.com/shuLhan/share/lib/contact" @@ -20,7 +20,7 @@ const ( func parseContact(t *testing.T) (contact *contact.Record) { googleContact := &Contact{} - jsonb, err := ioutil.ReadFile(sampleContact) + jsonb, err := os.ReadFile(sampleContact) if err != nil { t.Fatal(err) } diff --git a/lib/contact/google/google.go b/lib/contact/google/google.go index 466ee311..3660c743 100644 --- a/lib/contact/google/google.go +++ b/lib/contact/google/google.go @@ -9,7 +9,7 @@ package google import ( "encoding/json" - "io/ioutil" + "io" "net/http" "github.com/shuLhan/share/lib/contact" @@ -55,7 +55,7 @@ func ImportWithOAuth(client *http.Client) (contacts []*contact.Record, err error return } - resBody, err := ioutil.ReadAll(res.Body) + resBody, err := io.ReadAll(res.Body) if err != nil { return } diff --git a/lib/contact/google/google_test.go b/lib/contact/google/google_test.go index 8a5aa884..4cbf08e0 100644 --- a/lib/contact/google/google_test.go +++ b/lib/contact/google/google_test.go @@ -5,7 +5,7 @@ package google import ( - "io/ioutil" + "os" "testing" "github.com/shuLhan/share/lib/test" @@ -16,7 +16,7 @@ const ( ) func TestImportFromJSON(t *testing.T) { - jsonb, err := ioutil.ReadFile(sampleContacts) + jsonb, err := os.ReadFile(sampleContacts) if err != nil { t.Fatal(err) } diff --git a/lib/contact/microsoft/microsoft.go b/lib/contact/microsoft/microsoft.go index 995b47f0..d74139d5 100644 --- a/lib/contact/microsoft/microsoft.go +++ b/lib/contact/microsoft/microsoft.go @@ -13,7 +13,7 @@ package microsoft import ( "encoding/json" - "io/ioutil" + "io" "net/http" "github.com/shuLhan/share/lib/contact" @@ -61,7 +61,7 @@ func ImportWithOAuth(client *http.Client) (contacts []*contact.Record, err error return } - resBody, err := ioutil.ReadAll(res.Body) + resBody, err := io.ReadAll(res.Body) if err != nil { return } diff --git a/lib/contact/microsoft/microsoft_test.go b/lib/contact/microsoft/microsoft_test.go index b5f5a33f..226063ae 100644 --- a/lib/contact/microsoft/microsoft_test.go +++ b/lib/contact/microsoft/microsoft_test.go @@ -5,7 +5,7 @@ package microsoft import ( - "io/ioutil" + "os" "testing" "github.com/shuLhan/share/lib/contact" @@ -66,7 +66,7 @@ func TestImportFromJSON(t *testing.T) { JobTitle: "Tester", } - jsonb, err := ioutil.ReadFile(sampleContacts) + jsonb, err := os.ReadFile(sampleContacts) if err != nil { t.Fatal(err) } diff --git a/lib/contact/yahoo/contact_test.go b/lib/contact/yahoo/contact_test.go index 88ddfcaf..7f110742 100644 --- a/lib/contact/yahoo/contact_test.go +++ b/lib/contact/yahoo/contact_test.go @@ -5,7 +5,7 @@ package yahoo import ( - "io/ioutil" + "os" "testing" "github.com/shuLhan/share/lib/contact" @@ -17,7 +17,7 @@ const ( ) func parseSampleJSON(t *testing.T, input string) (contact *contact.Record) { - jsonb, err := ioutil.ReadFile(input) + jsonb, err := os.ReadFile(input) if err != nil { t.Fatal(err) } diff --git a/lib/contact/yahoo/contacts_test.go b/lib/contact/yahoo/contacts_test.go index ab7dbc27..d4bcd950 100644 --- a/lib/contact/yahoo/contacts_test.go +++ b/lib/contact/yahoo/contacts_test.go @@ -5,7 +5,7 @@ package yahoo import ( - "io/ioutil" + "os" "testing" "github.com/shuLhan/share/lib/test" @@ -16,7 +16,7 @@ const ( ) func TestImportFromJSON(t *testing.T) { - contactsb, err := ioutil.ReadFile(sampleContacts) + contactsb, err := os.ReadFile(sampleContacts) if err != nil { t.Fatal(err) } diff --git a/lib/contact/yahoo/yahoo.go b/lib/contact/yahoo/yahoo.go index b33b9338..ffc7f817 100644 --- a/lib/contact/yahoo/yahoo.go +++ b/lib/contact/yahoo/yahoo.go @@ -13,7 +13,7 @@ package yahoo import ( "encoding/json" - "io/ioutil" + "io" "net/http" "github.com/shuLhan/share/lib/contact" @@ -61,7 +61,7 @@ func ImportWithOAuth(client *http.Client, guid string) (contacts []*contact.Reco return } - resBody, err := ioutil.ReadAll(res.Body) + resBody, err := io.ReadAll(res.Body) if err != nil { return } diff --git a/lib/crypto/crypto.go b/lib/crypto/crypto.go index 9c815ba0..a2aa0803 100644 --- a/lib/crypto/crypto.go +++ b/lib/crypto/crypto.go @@ -12,14 +12,14 @@ import ( "crypto/x509" "encoding/pem" "fmt" - "io/ioutil" + "os" ) // // LoadPrivateKey read and parse PEM formatted private key from file. // func LoadPrivateKey(file string) (pkey *rsa.PrivateKey, err error) { - rawPEM, err := ioutil.ReadFile(file) + rawPEM, err := os.ReadFile(file) if err != nil { return nil, err } diff --git a/lib/dns/doh_client.go b/lib/dns/doh_client.go index 8ad3e924..16ddb4e9 100644 --- a/lib/dns/doh_client.go +++ b/lib/dns/doh_client.go @@ -9,7 +9,7 @@ import ( "crypto/tls" "encoding/base64" "fmt" - "io/ioutil" + "io" "net/http" "net/url" "time" @@ -139,7 +139,7 @@ func (cl *DoHClient) Lookup(q MessageQuestion, allowRecursion bool) (res *Messag // func (cl *DoHClient) Post(msg *Message) (*Message, error) { cl.req.Method = http.MethodPost - cl.req.Body = ioutil.NopCloser(bytes.NewReader(msg.packet)) + cl.req.Body = io.NopCloser(bytes.NewReader(msg.packet)) cl.req.URL.RawQuery = "" httpRes, err := cl.conn.Do(cl.req) @@ -151,7 +151,7 @@ func (cl *DoHClient) Post(msg *Message) (*Message, error) { res := NewMessage() - res.packet, err = ioutil.ReadAll(httpRes.Body) + res.packet, err = io.ReadAll(httpRes.Body) httpRes.Body.Close() if err != nil { return nil, err @@ -181,7 +181,7 @@ func (cl *DoHClient) Get(msg *Message) (*Message, error) { res := NewMessage() - res.packet, err = ioutil.ReadAll(httpRes.Body) + res.packet, err = io.ReadAll(httpRes.Body) httpRes.Body.Close() if err != nil { return nil, err diff --git a/lib/dns/server.go b/lib/dns/server.go index 6eff612e..24c74fd5 100644 --- a/lib/dns/server.go +++ b/lib/dns/server.go @@ -10,7 +10,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "log" "net" "net/http" @@ -542,7 +541,7 @@ func (srv *Server) handleDoHGet(w http.ResponseWriter, r *http.Request) { } func (srv *Server) handleDoHPost(w http.ResponseWriter, r *http.Request) { - raw, err := ioutil.ReadAll(r.Body) + raw, err := io.ReadAll(r.Body) if err != nil { w.WriteHeader(http.StatusBadRequest) return diff --git a/lib/dsv/common_test.go b/lib/dsv/common_test.go index 2133708d..548be036 100644 --- a/lib/dsv/common_test.go +++ b/lib/dsv/common_test.go @@ -8,7 +8,7 @@ import ( "bytes" "fmt" "io" - "io/ioutil" + "os" "runtime/debug" "testing" @@ -21,14 +21,14 @@ import ( // when both are different. // func assertFile(t *testing.T, a, b string) { - out, e := ioutil.ReadFile(a) + out, e := os.ReadFile(a) if e != nil { debug.PrintStack() t.Error(e) } - exp, e := ioutil.ReadFile(b) + exp, e := os.ReadFile(b) if e != nil { debug.PrintStack() diff --git a/lib/dsv/configinterface.go b/lib/dsv/configinterface.go index 2c6fd3ae..321f20c5 100644 --- a/lib/dsv/configinterface.go +++ b/lib/dsv/configinterface.go @@ -2,7 +2,7 @@ package dsv import ( "encoding/json" - "io/ioutil" + "os" "path" ) @@ -18,7 +18,7 @@ type ConfigInterface interface { // ConfigOpen configuration file and initialize the attributes. // func ConfigOpen(rw interface{}, fcfg string) error { - cfg, e := ioutil.ReadFile(fcfg) + cfg, e := os.ReadFile(fcfg) if nil != e { return e diff --git a/lib/email/dkim/dkim_test.go b/lib/email/dkim/dkim_test.go index 07b9505e..cfff75af 100644 --- a/lib/email/dkim/dkim_test.go +++ b/lib/email/dkim/dkim_test.go @@ -8,7 +8,7 @@ import ( "crypto/rsa" "crypto/x509" "encoding/pem" - "io/ioutil" + "os" "testing" "time" ) @@ -19,11 +19,11 @@ var ( ) func initKeys(t *testing.T) { - rsaPrivateRaw, err := ioutil.ReadFile("testdata/rsa.private.pem") + rsaPrivateRaw, err := os.ReadFile("testdata/rsa.private.pem") if err != nil { t.Fatal(err) } - rsaPublicRaw, err := ioutil.ReadFile("testdata/rsa.public.pem") + rsaPublicRaw, err := os.ReadFile("testdata/rsa.public.pem") if err != nil { t.Fatal(err) } diff --git a/lib/email/email_test.go b/lib/email/email_test.go index 2c4e5fbd..20163ee8 100644 --- a/lib/email/email_test.go +++ b/lib/email/email_test.go @@ -8,7 +8,6 @@ import ( "crypto/rsa" "crypto/x509" "encoding/pem" - "io/ioutil" "os" "testing" "time" @@ -30,11 +29,11 @@ func TestMain(m *testing.M) { } func initKeys(t *testing.T) { - rsaPrivateRaw, err := ioutil.ReadFile("dkim/testdata/rsa.private.pem") + rsaPrivateRaw, err := os.ReadFile("dkim/testdata/rsa.private.pem") if err != nil { t.Fatal(err) } - rsaPublicRaw, err := ioutil.ReadFile("dkim/testdata/rsa.public.pem") + rsaPublicRaw, err := os.ReadFile("dkim/testdata/rsa.public.pem") if err != nil { t.Fatal(err) } diff --git a/lib/email/maildir/manager.go b/lib/email/maildir/manager.go index aa96cff7..3bc06967 100644 --- a/lib/email/maildir/manager.go +++ b/lib/email/maildir/manager.go @@ -15,7 +15,6 @@ package maildir import ( "fmt" - "io/ioutil" "log" "os" "path/filepath" @@ -148,7 +147,7 @@ func (mg *Manager) OutQueue(email []byte) (err error) { return err } - err = ioutil.WriteFile(fname, email, 0400) + err = os.WriteFile(fname, email, 0400) if err != nil { err = fmt.Errorf("email/maildir: OutQueue: %s", err.Error()) return err @@ -193,7 +192,7 @@ func (mg *Manager) Incoming(email []byte) (err error) { return err } - err = ioutil.WriteFile(tmpFile, email, 0660) + err = os.WriteFile(tmpFile, email, 0660) if err != nil { err = fmt.Errorf("email/maildir: Incoming: %s", err.Error()) return err diff --git a/lib/email/message.go b/lib/email/message.go index 731b8bf8..1e334f95 100644 --- a/lib/email/message.go +++ b/lib/email/message.go @@ -8,7 +8,6 @@ import ( "bytes" "crypto/rsa" "fmt" - "io/ioutil" "os" "strings" "time" @@ -93,7 +92,7 @@ func NewMultipart(from, to, subject, bodyText, bodyHTML []byte) ( // ParseFile parse message from file. // func ParseFile(inFile string) (msg *Message, rest []byte, err error) { - raw, err := ioutil.ReadFile(inFile) + raw, err := os.ReadFile(inFile) if err != nil { return nil, nil, fmt.Errorf("email: " + err.Error()) } diff --git a/lib/email/message_test.go b/lib/email/message_test.go index 7a52a0c2..c7957b57 100644 --- a/lib/email/message_test.go +++ b/lib/email/message_test.go @@ -5,7 +5,6 @@ package email import ( - "io/ioutil" "os" "testing" @@ -126,7 +125,7 @@ func TestMessageParseMessage(t *testing.T) { for _, c := range cases { t.Log(c.in) - in, err := ioutil.ReadFile(c.in) + in, err := os.ReadFile(c.in) if err != nil { t.Fatal(err) } diff --git a/lib/http/client.go b/lib/http/client.go index 35f0cdb5..9d201933 100644 --- a/lib/http/client.go +++ b/lib/http/client.go @@ -15,7 +15,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "log" "mime/multipart" "net" @@ -131,7 +130,7 @@ func (client *Client) Do(httpRequest *http.Request) ( } } - rawBody, err := ioutil.ReadAll(httpRes.Body) + rawBody, err := io.ReadAll(httpRes.Body) if err != nil { return nil, nil, fmt.Errorf("%s: %w", logp, err) } @@ -486,7 +485,7 @@ func (client *Client) uncompress(res *http.Response, body []byte) ( switch res.Header.Get(HeaderContentEncoding) { case ContentEncodingBzip2: - dec = ioutil.NopCloser(bzip2.NewReader(in)) + dec = io.NopCloser(bzip2.NewReader(in)) case ContentEncodingCompress: dec = lzw.NewReader(in, lzw.MSB, 8) diff --git a/lib/http/endpoint.go b/lib/http/endpoint.go index bce29eba..d0def1aa 100644 --- a/lib/http/endpoint.go +++ b/lib/http/endpoint.go @@ -6,7 +6,7 @@ package http import ( "bytes" - "io/ioutil" + "io" "net/http" "net/url" @@ -89,7 +89,7 @@ func (ep *Endpoint) call( e error ) - epr.RequestBody, e = ioutil.ReadAll(req.Body) + epr.RequestBody, e = io.ReadAll(req.Body) if e != nil { mlog.Errf("%s: ReadAll: %s", logp, e) res.WriteHeader(http.StatusBadRequest) @@ -97,7 +97,7 @@ func (ep *Endpoint) call( } req.Body.Close() - req.Body = ioutil.NopCloser(bytes.NewBuffer(epr.RequestBody)) + req.Body = io.NopCloser(bytes.NewBuffer(epr.RequestBody)) switch ep.RequestType { case RequestTypeForm, RequestTypeQuery, RequestTypeJSON: diff --git a/lib/http/http.go b/lib/http/http.go index 60094576..b055e64c 100644 --- a/lib/http/http.go +++ b/lib/http/http.go @@ -156,7 +156,7 @@ // HttpWriter: w, // HttpRequest: req, // } -// epr.RequestBody, _ = ioutil.ReadAll(req.Body) +// epr.RequestBody, _ = io.ReadAll(req.Body) // // // Check request type, and call ParseForm or // // ParseMultipartForm if required. diff --git a/lib/http/server.go b/lib/http/server.go index 572edaee..afa952b1 100644 --- a/lib/http/server.go +++ b/lib/http/server.go @@ -8,7 +8,6 @@ import ( "context" "errors" "fmt" - "io/ioutil" "net/http" "os" "path" @@ -533,7 +532,7 @@ func (srv *Server) HandleFS(res http.ResponseWriter, req *http.Request) { body = node.Content size = node.Size() } else { - body, err = ioutil.ReadFile(node.SysPath) + body, err = os.ReadFile(node.SysPath) if err != nil { res.WriteHeader(http.StatusInternalServerError) return diff --git a/lib/http/server_test.go b/lib/http/server_test.go index d613d2a8..5b73d230 100644 --- a/lib/http/server_test.go +++ b/lib/http/server_test.go @@ -7,7 +7,7 @@ package http import ( "bytes" "fmt" - "io/ioutil" + "io" "net/http" "testing" @@ -147,7 +147,7 @@ func TestRegisterDelete(t *testing.T) { t.Fatal(e) } - body, e := ioutil.ReadAll(res.Body) + body, e := io.ReadAll(res.Body) if e != nil { t.Fatal(e) } @@ -225,7 +225,7 @@ func TestRegisterEvaluator(t *testing.T) { t.Fatal(e) } - _, e = ioutil.ReadAll(res.Body) + _, e = io.ReadAll(res.Body) if e != nil { t.Fatal(e) } @@ -293,7 +293,7 @@ func TestRegisterGet(t *testing.T) { t.Fatal(e) } - body, e := ioutil.ReadAll(res.Body) + body, e := io.ReadAll(res.Body) if e != nil { t.Fatal(e) } @@ -360,7 +360,7 @@ func TestRegisterHead(t *testing.T) { t.Fatal(e) } - body, e := ioutil.ReadAll(res.Body) + body, e := io.ReadAll(res.Body) if e != nil { t.Fatal(e) } @@ -424,7 +424,7 @@ func TestRegisterPatch(t *testing.T) { t.Fatal(e) } - body, e := ioutil.ReadAll(res.Body) + body, e := io.ReadAll(res.Body) if e != nil { t.Fatal(e) } @@ -496,7 +496,7 @@ k=vv`, t.Fatal(e) } - body, e := ioutil.ReadAll(res.Body) + body, e := io.ReadAll(res.Body) if e != nil { t.Fatal(e) } @@ -555,7 +555,7 @@ func TestRegisterPut(t *testing.T) { t.Fatal(e) } - body, e := ioutil.ReadAll(res.Body) + body, e := io.ReadAll(res.Body) if e != nil { t.Fatal(e) } @@ -773,7 +773,7 @@ func TestStatusError(t *testing.T) { t.Fatal(e) } - body, e := ioutil.ReadAll(res.Body) + body, e := io.ReadAll(res.Body) if e != nil { t.Fatal(e) } @@ -865,7 +865,7 @@ func TestServer_Options_HandleFS(t *testing.T) { test.Assert(t, c.desc, c.expStatusCode, res.StatusCode) - gotBody, err := ioutil.ReadAll(res.Body) + gotBody, err := io.ReadAll(res.Body) if err != nil { t.Fatalf("%s: %s", c.desc, err) } diff --git a/lib/hunspell/dictionary.go b/lib/hunspell/dictionary.go index c445d46c..8caa2290 100644 --- a/lib/hunspell/dictionary.go +++ b/lib/hunspell/dictionary.go @@ -6,8 +6,8 @@ package hunspell import ( "fmt" - "io/ioutil" "log" + "os" "strconv" "strings" @@ -20,7 +20,7 @@ type dictionary struct { } func (dict *dictionary) open(file string, opts *affixOptions) (err error) { - content, err := ioutil.ReadFile(file) + content, err := os.ReadFile(file) if err != nil { return fmt.Errorf("dictionary.open: %w", err) } diff --git a/lib/hunspell/hunspell_test.go b/lib/hunspell/hunspell_test.go index 70e7101e..b7d710af 100644 --- a/lib/hunspell/hunspell_test.go +++ b/lib/hunspell/hunspell_test.go @@ -5,7 +5,7 @@ package hunspell import ( - "io/ioutil" + "os" "testing" "github.com/shuLhan/share/lib/test" @@ -59,7 +59,7 @@ work/B continue } - got, err := ioutil.ReadFile(c.outFile) + got, err := os.ReadFile(c.outFile) if err != nil { t.Fatalf("%s: %s", c.desc, err) } diff --git a/lib/hunspell/options.go b/lib/hunspell/options.go index dbc94551..4d7b59c8 100644 --- a/lib/hunspell/options.go +++ b/lib/hunspell/options.go @@ -6,8 +6,8 @@ package hunspell import ( "fmt" - "io/ioutil" "log" + "os" "regexp" "strconv" "strings" @@ -162,7 +162,7 @@ type affixOptions struct { // its default values. // func (opts *affixOptions) open(file string) (err error) { - affcontent, err := ioutil.ReadFile(file) + affcontent, err := os.ReadFile(file) if err != nil { return fmt.Errorf("affixOptions.open: %w", err) } diff --git a/lib/ini/reader.go b/lib/ini/reader.go index eb6ddbfb..cc8ac20b 100644 --- a/lib/ini/reader.go +++ b/lib/ini/reader.go @@ -9,7 +9,7 @@ import ( "errors" "fmt" "io" - "io/ioutil" + "os" "unicode" "github.com/shuLhan/share/lib/debug" @@ -98,7 +98,7 @@ func (reader *reader) reset(src []byte) { // On failure, it return nil and error. // func (reader *reader) parseFile(filename string) (in *Ini, err error) { - src, err := ioutil.ReadFile(filename) + src, err := os.ReadFile(filename) if err != nil { return } diff --git a/lib/ini/reader_bench_test.go b/lib/ini/reader_bench_test.go index 71e195ac..0721784d 100644 --- a/lib/ini/reader_bench_test.go +++ b/lib/ini/reader_bench_test.go @@ -5,7 +5,7 @@ package ini import ( - "io/ioutil" + "os" "testing" ) @@ -24,7 +24,7 @@ import ( // func BenchmarkParse(b *testing.B) { reader := newReader() - src, err := ioutil.ReadFile(testdataInputIni) + src, err := os.ReadFile(testdataInputIni) if err != nil { b.Fatal(err) } diff --git a/lib/io/io_test.go b/lib/io/io_test.go index 75c1ab8b..0d0f6a71 100644 --- a/lib/io/io_test.go +++ b/lib/io/io_test.go @@ -5,7 +5,6 @@ package io import ( - "io/ioutil" "os" "testing" @@ -85,7 +84,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. continue } - got, err := ioutil.ReadFile(c.out) + got, err := os.ReadFile(c.out) if err != nil { t.Fatal(err) } diff --git a/lib/io/reader.go b/lib/io/reader.go index a3f8319a..163ae6f8 100644 --- a/lib/io/reader.go +++ b/lib/io/reader.go @@ -5,7 +5,7 @@ package io import ( - "io/ioutil" + "os" "github.com/shuLhan/share/lib/ascii" ) @@ -35,7 +35,7 @@ func NewReader(path string) (*Reader, error) { var err error r := new(Reader) - r.V, err = ioutil.ReadFile(path) + r.V, err = os.ReadFile(path) if err != nil { return nil, err } diff --git a/lib/memfs/dirwatcher_example_test.go b/lib/memfs/dirwatcher_example_test.go index a8468d80..885bec92 100644 --- a/lib/memfs/dirwatcher_example_test.go +++ b/lib/memfs/dirwatcher_example_test.go @@ -6,7 +6,6 @@ package memfs import ( "fmt" - "io/ioutil" "log" "os" "path/filepath" @@ -20,7 +19,7 @@ func ExampleDirWatcher() { err error ) - rootDir, err = ioutil.TempDir("", "libmemfs") + rootDir, err = os.MkdirTemp("", "libmemfs") if err != nil { log.Fatal(err) } @@ -80,7 +79,7 @@ func ExampleDirWatcher() { newFile := filepath.Join(rootDir, "new.adoc") fmt.Println("Create new file on root directory: /new.adoc") - err = ioutil.WriteFile(newFile, nil, 0600) + err = os.WriteFile(newFile, nil, 0600) if err != nil { log.Fatal(err) } @@ -108,7 +107,7 @@ func ExampleDirWatcher() { // Add new file in sub directory. newFile = filepath.Join(subDir, "new.adoc") fmt.Println("Create new file in sub directory: /subdir/new.adoc") - err = ioutil.WriteFile(newFile, nil, 0600) + err = os.WriteFile(newFile, nil, 0600) if err != nil { log.Fatal(err) } @@ -126,7 +125,7 @@ func ExampleDirWatcher() { // Creating file that is excluded should not trigger event. newFile = filepath.Join(subDir, "new.html") fmt.Println("Create excluded file in sub directory: /subdir/new.html") - err = ioutil.WriteFile(newFile, nil, 0600) + err = os.WriteFile(newFile, nil, 0600) if err != nil { log.Fatal(err) } @@ -135,7 +134,7 @@ func ExampleDirWatcher() { // event. newFile = filepath.Join(dirAssets, "new") fmt.Println("Create new file under assets: /assets/new") - err = ioutil.WriteFile(newFile, nil, 0600) + err = os.WriteFile(newFile, nil, 0600) if err != nil { log.Fatal(err) } diff --git a/lib/memfs/doc.go b/lib/memfs/doc.go index 56aa1083..4c9cab7b 100644 --- a/lib/memfs/doc.go +++ b/lib/memfs/doc.go @@ -46,7 +46,7 @@ // } // if node.Content == nil { // // Handle large file. -// node.V, err = ioutil.ReadFile(child.SysPath) +// node.V, err = os.ReadFile(child.SysPath) // } // // Do something with content of file system. // diff --git a/lib/memfs/memfs_example_test.go b/lib/memfs/memfs_example_test.go index d6fef23e..04eb0d9e 100644 --- a/lib/memfs/memfs_example_test.go +++ b/lib/memfs/memfs_example_test.go @@ -2,7 +2,6 @@ package memfs import ( "fmt" - "io/ioutil" "log" "os" "path/filepath" @@ -106,7 +105,7 @@ func ExampleMemFS_Watch() { err error ) - opts.Root, err = ioutil.TempDir("", "memfs_watch") + opts.Root, err = os.MkdirTemp("", "memfs_watch") if err != nil { log.Fatal(err) } diff --git a/lib/memfs/node.go b/lib/memfs/node.go index 72b62731..752d5fdf 100644 --- a/lib/memfs/node.go +++ b/lib/memfs/node.go @@ -10,7 +10,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "mime" "net/http" "os" @@ -510,7 +509,7 @@ func (node *Node) updateContent(maxFileSize int64) (err error) { return nil } - node.Content, err = ioutil.ReadFile(node.SysPath) + node.Content, err = os.ReadFile(node.SysPath) if err != nil { if errors.Is(err, io.EOF) { return nil diff --git a/lib/memfs/watcher_example_test.go b/lib/memfs/watcher_example_test.go index 9ef7d8e2..94f260ee 100644 --- a/lib/memfs/watcher_example_test.go +++ b/lib/memfs/watcher_example_test.go @@ -6,7 +6,6 @@ package memfs import ( "fmt" - "io/ioutil" "log" "os" "time" @@ -23,7 +22,7 @@ func ExampleNewWatcher() { ) // Create a file to be watched. - f, err = ioutil.TempFile("", "watcher") + f, err = os.CreateTemp("", "watcher") if err != nil { log.Fatal(err) } diff --git a/lib/parser/parser.go b/lib/parser/parser.go index 33897ba7..23beeedb 100644 --- a/lib/parser/parser.go +++ b/lib/parser/parser.go @@ -9,7 +9,7 @@ package parser import ( "fmt" - "io/ioutil" + "os" libascii "github.com/shuLhan/share/lib/ascii" ) @@ -56,7 +56,7 @@ func New(content, delims string) (p *Parser) { // If delimiters is empty, it would default to all whitespaces characters. // func Open(file, delims string) (p *Parser, err error) { - v, err := ioutil.ReadFile(file) + v, err := os.ReadFile(file) if err != nil { return nil, err } diff --git a/lib/smtp/localstorage.go b/lib/smtp/localstorage.go index 6fb4a7b0..a3c8e0f2 100644 --- a/lib/smtp/localstorage.go +++ b/lib/smtp/localstorage.go @@ -7,7 +7,6 @@ package smtp import ( "bytes" "encoding/gob" - "io/ioutil" "log" "os" "path/filepath" @@ -93,7 +92,7 @@ func (fs *LocalStorage) MailLoad(id string) (mail *MailTx, err error) { fpath := filepath.Join(fs.dir, id) - b, err := ioutil.ReadFile(fpath) + b, err := os.ReadFile(fpath) if err != nil { return nil, err } @@ -148,7 +147,7 @@ func (fs *LocalStorage) MailSave(mail *MailTx) (err error) { fpath := filepath.Join(fs.dir, mail.ID) - return ioutil.WriteFile(fpath, fs.buff.Bytes(), 0600) + return os.WriteFile(fpath, fs.buff.Bytes(), 0600) } func (fs *LocalStorage) loadRaw(b []byte) (mail *MailTx, err error) { diff --git a/lib/sql/client.go b/lib/sql/client.go index aa260307..bb2ad351 100644 --- a/lib/sql/client.go +++ b/lib/sql/client.go @@ -9,7 +9,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "log" "net/http" "os" @@ -307,7 +306,7 @@ func loadSQL(fs http.FileSystem, fi os.FileInfo, filename string) ( return nil, fmt.Errorf("%s: %w", logp, err) } - sqlRaw, err = ioutil.ReadAll(file) + sqlRaw, err = io.ReadAll(file) if err != nil { if !errors.Is(err, io.EOF) { return nil, fmt.Errorf("%s: %w", logp, err) diff --git a/lib/ssh/config/parser.go b/lib/ssh/config/parser.go index f238c017..52cc58bd 100644 --- a/lib/ssh/config/parser.go +++ b/lib/ssh/config/parser.go @@ -8,7 +8,6 @@ import ( "bytes" "errors" "fmt" - "io/ioutil" "os" "path/filepath" "strings" @@ -206,7 +205,7 @@ func parseInclude(line string) (patterns []string) { // Any empty lines or line start with comment '#' will be removed. // func readLines(file string) (lines []string, err error) { - contents, err := ioutil.ReadFile(file) + contents, err := os.ReadFile(file) if err != nil { if errors.Is(err, os.ErrNotExist) { return nil, nil diff --git a/lib/ssh/config/section.go b/lib/ssh/config/section.go index 7dc18151..b27458f8 100644 --- a/lib/ssh/config/section.go +++ b/lib/ssh/config/section.go @@ -7,7 +7,6 @@ package config import ( "errors" "fmt" - "io/ioutil" "os" "path/filepath" "strings" @@ -158,7 +157,7 @@ func (section *Section) GenerateSigners(agentc agent.ExtendedAgent) (err error) section.Signers = make([]ssh.Signer, 0, len(section.IdentityFile)) for _, pkeyFile = range section.IdentityFile { - pkeyPem, err = ioutil.ReadFile(pkeyFile) + pkeyPem, err = os.ReadFile(pkeyFile) if err != nil { if errors.Is(err, os.ErrNotExist) { continue diff --git a/lib/tabula/datasetinterface.go b/lib/tabula/datasetinterface.go index 2ace851e..dac38fed 100644 --- a/lib/tabula/datasetinterface.go +++ b/lib/tabula/datasetinterface.go @@ -7,7 +7,7 @@ package tabula import ( "encoding/json" "fmt" - "io/ioutil" + "os" "github.com/shuLhan/share/lib/debug" ) @@ -69,7 +69,7 @@ type DatasetInterface interface { // field from there. // func ReadDatasetConfig(ds interface{}, fcfg string) (e error) { - cfg, e := ioutil.ReadFile(fcfg) + cfg, e := os.ReadFile(fcfg) if nil != e { return e diff --git a/lib/test/mock/mock.go b/lib/test/mock/mock.go index aa8810db..62e83b3b 100644 --- a/lib/test/mock/mock.go +++ b/lib/test/mock/mock.go @@ -7,7 +7,6 @@ package mock import ( "io" - "io/ioutil" "log" "os" ) @@ -64,7 +63,7 @@ func Error() string { ResetStderr(false) - bs, err := ioutil.ReadAll(_stderr) + bs, err := io.ReadAll(_stderr) if err != nil { log.Fatal(err) } @@ -82,7 +81,7 @@ func Output() string { ResetStdout(false) - bs, err := ioutil.ReadAll(_stdout) + bs, err := io.ReadAll(_stdout) if err != nil { log.Fatal(err) } @@ -96,7 +95,7 @@ func Output() string { func Stderr() *os.File { var err error - _stderr, err = ioutil.TempFile("", "") + _stderr, err = os.CreateTemp("", "") if err != nil { log.Fatal(err) } @@ -110,7 +109,7 @@ func Stderr() *os.File { func Stdin() *os.File { var err error - _stdin, err = ioutil.TempFile("", "") + _stdin, err = os.CreateTemp("", "") if err != nil { log.Fatal(err) } @@ -124,7 +123,7 @@ func Stdin() *os.File { func Stdout() *os.File { var err error - _stdout, err = ioutil.TempFile("", "") + _stdout, err = os.CreateTemp("", "") if err != nil { log.Fatal(err) } |
