io/ioutil
package usage GO-C400110)
11
12func serveTMs() *httptest.Server {
13 tms, err := ioutil.ReadFile("./testFiles/tms.json")14 if err != nil {
15 log.Printf("Error reading file: %s", err)
16 return nil
10)
11
12func serveTBs() *httptest.Server {
13 tbs, err := ioutil.ReadFile("./testFiles/tbs.json")14 if err != nil {
15 log.Printf("Error reading file: %s", err)
16 return nil
60}
61
62func (app *Application) login() (bool, error) {
63 credentials, err := ioutil.ReadFile("./secrets.json")64 if err != nil {
65 return false, fmt.Errorf("Error reading credentials: %s", err)
66 }
io/ioutil
package, like most things with util in the name, has turned out to
be a poorly defined and complex to understand the collection of things.
In a series of a few changes, the entire ioutil package will become deprecated starting from Go 1.16.
Existing code using ioutil will continue to work; ioutil will consist of simple wrappers to new functions which reside in the io and os packages.
ioutil.ReadAll(r)
ioutil.ReadFile(filename)
ioutil.ReadDir(dirname)
// ...
io.ReadAll(r)
os.ReadFile(filename)
os.ReadDir(dirname)
// ...