mirror of
https://github.com/taigrr/wails.git
synced 2026-04-02 05:08:54 -07:00
refactor: move from io/ioutil to io and os packages
The io/ioutil package has been deprecated as of Go 1.16, see https://golang.org/doc/go1.16#ioutil. This commit replaces the existing io/ioutil functions with their new definitions in io and os packages. Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
This commit is contained in:
@@ -3,7 +3,6 @@ package build
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
@@ -87,7 +86,7 @@ func (b *BaseBuilder) buildCustomAssets(projectData *project.Project) error {
|
||||
if len(localPath) == 0 {
|
||||
return nil
|
||||
}
|
||||
if data, err := ioutil.ReadFile(filepath.Join(customAssetsDir, localPath)); err == nil {
|
||||
if data, err := os.ReadFile(filepath.Join(customAssetsDir, localPath)); err == nil {
|
||||
assets.AddAsset(localPath, data)
|
||||
}
|
||||
|
||||
@@ -100,7 +99,7 @@ func (b *BaseBuilder) buildCustomAssets(projectData *project.Project) error {
|
||||
// Write assetdb out to root directory
|
||||
assetsDbFilename := fs.RelativePath("../../../assetsdb.go")
|
||||
b.addFileToDelete(assetsDbFilename)
|
||||
err = ioutil.WriteFile(assetsDbFilename, []byte(assets.Serialize("assets", "wails")), 0644)
|
||||
err = os.WriteFile(assetsDbFilename, []byte(assets.Serialize("assets", "wails")), 0644)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -108,7 +107,7 @@ func (b *BaseBuilder) buildCustomAssets(projectData *project.Project) error {
|
||||
}
|
||||
|
||||
func (b *BaseBuilder) convertFileToIntegerString(filename string) (string, error) {
|
||||
rawData, err := ioutil.ReadFile(filename)
|
||||
rawData, err := os.ReadFile(filename)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
@@ -2,12 +2,12 @@ package build
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/wailsapp/wails/v2/pkg/buildassets"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/wailsapp/wails/v2/internal/fs"
|
||||
"github.com/wailsapp/wails/v2/internal/html"
|
||||
"github.com/wailsapp/wails/v2/pkg/buildassets"
|
||||
)
|
||||
|
||||
// DesktopBuilder builds applications for the desktop
|
||||
@@ -138,7 +138,7 @@ func (d *DesktopBuilder) BuildRuntime(options *Options) error {
|
||||
}
|
||||
|
||||
wailsJS := fs.RelativePath("../../../internal/runtime/assets/desktop.js")
|
||||
runtimeData, err := ioutil.ReadFile(wailsJS)
|
||||
runtimeData, err := os.ReadFile(wailsJS)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -158,7 +158,7 @@ const unsigned char runtime[]={`
|
||||
// Save file
|
||||
outputFile := fs.RelativePath("../../../internal/ffenestri/runtime.c")
|
||||
|
||||
if err := ioutil.WriteFile(outputFile, []byte(runtimeC), 0600); err != nil {
|
||||
if err := os.WriteFile(outputFile, []byte(runtimeC), 0600); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@ package build
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
@@ -75,7 +74,7 @@ func (d *DesktopBuilder) processTrayIcons(assetDir string, options *Options) err
|
||||
for count, filename := range trayIconFilenames {
|
||||
|
||||
// Load the tray icon
|
||||
dataBytes, err = ioutil.ReadFile(filename)
|
||||
dataBytes, err = os.ReadFile(filename)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -110,7 +109,7 @@ func (d *DesktopBuilder) processTrayIcons(assetDir string, options *Options) err
|
||||
}
|
||||
cdata.WriteString("0x00 };\n")
|
||||
|
||||
err = ioutil.WriteFile(targetFile, []byte(cdata.String()), 0600)
|
||||
err = os.WriteFile(targetFile, []byte(cdata.String()), 0600)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -169,7 +168,7 @@ func (d *DesktopBuilder) processDialogIcons(assetDir string, options *Options) e
|
||||
for count, filename := range dialogIconFilenames {
|
||||
|
||||
// Load the tray icon
|
||||
dataBytes, err = ioutil.ReadFile(filename)
|
||||
dataBytes, err = os.ReadFile(filename)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -204,7 +203,7 @@ func (d *DesktopBuilder) processDialogIcons(assetDir string, options *Options) e
|
||||
}
|
||||
cdata.WriteString("0x00 };\n")
|
||||
|
||||
err = ioutil.WriteFile(targetFile, []byte(cdata.String()), 0600)
|
||||
err = os.WriteFile(targetFile, []byte(cdata.String()), 0600)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ package build
|
||||
|
||||
import (
|
||||
"image/png"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
@@ -52,7 +51,7 @@ func (d *DesktopBuilder) compileIcon(assetDir string, iconFile string) error {
|
||||
output = strings.Replace(output, "static char", "const char", 1)
|
||||
|
||||
// save icon.c
|
||||
err = ioutil.WriteFile(targetFile, []byte(output), 0755)
|
||||
err = os.WriteFile(targetFile, []byte(output), 0755)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -2,12 +2,13 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/leaanthony/slicer"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/leaanthony/slicer"
|
||||
)
|
||||
|
||||
func convertToHexLiteral(bytes []byte) string {
|
||||
@@ -56,7 +57,7 @@ func buildMacIcons(dialogIconFilenames []string) error {
|
||||
for count, filename := range dialogIconFilenames {
|
||||
|
||||
// Load the tray icon
|
||||
dataBytes, err = ioutil.ReadFile(filename)
|
||||
dataBytes, err = os.ReadFile(filename)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
@@ -91,7 +92,7 @@ func buildMacIcons(dialogIconFilenames []string) error {
|
||||
}
|
||||
cdata.WriteString("0x00 };\n")
|
||||
|
||||
err = ioutil.WriteFile(targetFile, []byte(cdata.String()), 0600)
|
||||
err = os.WriteFile(targetFile, []byte(cdata.String()), 0600)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package build
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
@@ -73,7 +72,7 @@ func (s *ServerBuilder) BuildBaseAssets(assets *html.AssetBundle) error {
|
||||
|
||||
// Add wails.js
|
||||
wailsjsPath := fs.RelativePath("../../../internal/runtime/assets/server.js")
|
||||
if rawData, err := ioutil.ReadFile(wailsjsPath); err == nil {
|
||||
if rawData, err := os.ReadFile(wailsjsPath); err == nil {
|
||||
db.AddAsset("/wails.js", rawData)
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"bytes"
|
||||
_ "embed"
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
@@ -44,7 +44,7 @@ func main() {
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
data, err := ioutil.ReadAll(resp.Body)
|
||||
data, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ package parser
|
||||
import (
|
||||
"bytes"
|
||||
_ "embed"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"text/template"
|
||||
@@ -135,7 +134,7 @@ func generatePackage(pkg *Package, moduledir string) error {
|
||||
}
|
||||
|
||||
// Save typescript file
|
||||
err = ioutil.WriteFile(filepath.Join(moduledir, "_"+pkg.Name+".d.ts"), buffer.Bytes(), 0755)
|
||||
err = os.WriteFile(filepath.Join(moduledir, "_"+pkg.Name+".d.ts"), buffer.Bytes(), 0755)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "Error writing backend package file")
|
||||
}
|
||||
@@ -156,7 +155,7 @@ func generatePackage(pkg *Package, moduledir string) error {
|
||||
}
|
||||
|
||||
// Save javascript file
|
||||
err = ioutil.WriteFile(filepath.Join(moduledir, "_"+pkg.Name+".js"), buffer.Bytes(), 0755)
|
||||
err = os.WriteFile(filepath.Join(moduledir, "_"+pkg.Name+".js"), buffer.Bytes(), 0755)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "Error writing backend package file")
|
||||
}
|
||||
@@ -183,7 +182,7 @@ func generateIndexJS(dir string, packages []*Package) error {
|
||||
// Calculate target filename
|
||||
indexJS := filepath.Join(dir, "index.js")
|
||||
|
||||
err = ioutil.WriteFile(indexJS, buffer.Bytes(), 0755)
|
||||
err = os.WriteFile(indexJS, buffer.Bytes(), 0755)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "Error writing backend package index.js file")
|
||||
}
|
||||
@@ -209,7 +208,7 @@ func generateIndexTS(dir string, packages []*Package) error {
|
||||
// Calculate target filename
|
||||
indexJS := filepath.Join(dir, "index.d.ts")
|
||||
|
||||
err = ioutil.WriteFile(indexJS, buffer.Bytes(), 0755)
|
||||
err = os.WriteFile(indexJS, buffer.Bytes(), 0755)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "Error writing backend package index.d.ts file")
|
||||
}
|
||||
@@ -236,7 +235,7 @@ func generateGlobalsTS(dir string, packages []*Package) error {
|
||||
// Calculate target filename
|
||||
indexJS := filepath.Join(dir, "globals.d.ts")
|
||||
|
||||
err = ioutil.WriteFile(indexJS, buffer.Bytes(), 0755)
|
||||
err = os.WriteFile(indexJS, buffer.Bytes(), 0755)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "Error writing backend package globals.d.ts file")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user