5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-02 23:51:44 +08: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:
Eng Zer Jun 2021-11-25 12:09:23 +08:00
parent ae341be638
commit ef8d7d2fd7
No known key found for this signature in database
GPG Key ID: DAEBBD2E34C111E6
26 changed files with 73 additions and 89 deletions

View File

@ -6,7 +6,6 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"log" "log"
"os" "os"
"path" "path"
@ -50,7 +49,7 @@ func (fs *FSHelper) FileExists(path string) bool {
// FindFile returns the first occurrence of match inside path. // FindFile returns the first occurrence of match inside path.
func (fs *FSHelper) FindFile(path, match string) (string, error) { func (fs *FSHelper) FindFile(path, match string) (string, error) {
files, err := ioutil.ReadDir(path) files, err := os.ReadDir(path)
if err != nil { if err != nil {
return "", err return "", err
} }
@ -69,7 +68,7 @@ func (fs *FSHelper) FindFile(path, match string) (string, error) {
func (fs *FSHelper) CreateFile(filename string, data []byte) error { func (fs *FSHelper) CreateFile(filename string, data []byte) error {
// Ensure directory exists // Ensure directory exists
fs.MkDirs(filepath.Dir(filename)) fs.MkDirs(filepath.Dir(filename))
return ioutil.WriteFile(filename, data, 0644) return os.WriteFile(filename, data, 0644)
} }
// MkDirs creates the given nested directories. // MkDirs creates the given nested directories.
@ -156,14 +155,14 @@ func (fs *FSHelper) LoadRelativeFile(relativePath string) ([]byte, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
return ioutil.ReadFile(fullPath) return os.ReadFile(fullPath)
} }
// GetSubdirs will return a list of FQPs to subdirectories in the given directory // GetSubdirs will return a list of FQPs to subdirectories in the given directory
func (d *Dir) GetSubdirs() (map[string]string, error) { func (d *Dir) GetSubdirs() (map[string]string, error) {
// Read in the directory information // Read in the directory information
fileInfo, err := ioutil.ReadDir(d.fullPath) fileInfo, err := os.ReadDir(d.fullPath)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -215,7 +214,7 @@ func (fs *FSHelper) SaveAsJSON(data interface{}, filename string) error {
e.SetIndent("", " ") e.SetIndent("", " ")
e.Encode(data) e.Encode(data)
err := ioutil.WriteFile(filename, buf.Bytes(), 0755) err := os.WriteFile(filename, buf.Bytes(), 0755)
if err != nil { if err != nil {
return err return err
} }
@ -231,7 +230,7 @@ func (fs *FSHelper) LoadAsString(filename string) (string, error) {
// LoadAsBytes returns the contents of the file as a byte slice // LoadAsBytes returns the contents of the file as a byte slice
func (fs *FSHelper) LoadAsBytes(filename string) ([]byte, error) { func (fs *FSHelper) LoadAsBytes(filename string) ([]byte, error) {
return ioutil.ReadFile(filename) return os.ReadFile(filename)
} }
// FileMD5 returns the md5sum of the given file // FileMD5 returns the md5sum of the given file

View File

@ -3,7 +3,7 @@ package cmd
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil" "io"
"net/http" "net/http"
"sort" "sort"
) )
@ -28,7 +28,7 @@ func (g *GitHubHelper) GetVersionTags() ([]*SemanticVersion, error) {
if err != nil { if err != nil {
return result, err return result, err
} }
body, err := ioutil.ReadAll(resp.Body) body, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
return result, err return result, err
} }

View File

@ -2,7 +2,6 @@ package cmd
import ( import (
"fmt" "fmt"
"io/ioutil"
"net/url" "net/url"
"os" "os"
"runtime" "runtime"
@ -95,7 +94,7 @@ func GetLinuxDistroInfo() *DistroInfo {
} }
_, err := os.Stat("/etc/os-release") _, err := os.Stat("/etc/os-release")
if !os.IsNotExist(err) { if !os.IsNotExist(err) {
osRelease, _ := ioutil.ReadFile("/etc/os-release") osRelease, _ := os.ReadFile("/etc/os-release")
result = parseOsRelease(string(osRelease)) result = parseOsRelease(string(osRelease))
} }
return result return result

View File

@ -7,7 +7,6 @@ import (
"fmt" "fmt"
"image" "image"
"image/png" "image/png"
"io/ioutil"
"os" "os"
"path" "path"
"path/filepath" "path/filepath"
@ -244,7 +243,7 @@ func (b *PackageHelper) packageOSX(po *ProjectOptions) error {
// No - create a new plist from our defaults // No - create a new plist from our defaults
tmpl := template.New("infoPlist") tmpl := template.New("infoPlist")
plistFile := filepath.Join(b.getPackageFileBaseDir(), "info.plist") plistFile := filepath.Join(b.getPackageFileBaseDir(), "info.plist")
infoPlist, err := ioutil.ReadFile(plistFile) infoPlist, err := os.ReadFile(plistFile)
if err != nil { if err != nil {
return err return err
} }
@ -258,13 +257,13 @@ func (b *PackageHelper) packageOSX(po *ProjectOptions) error {
} }
// Save to the package // Save to the package
err = ioutil.WriteFile(plistFilename, tpl.Bytes(), 0644) err = os.WriteFile(plistFilename, tpl.Bytes(), 0644)
if err != nil { if err != nil {
return err return err
} }
// Also write to project directory for customisation // Also write to project directory for customisation
err = ioutil.WriteFile(customPlist, tpl.Bytes(), 0644) err = os.WriteFile(customPlist, tpl.Bytes(), 0644)
if err != nil { if err != nil {
return err return err
} }
@ -334,12 +333,12 @@ func (b *PackageHelper) PackageWindows(po *ProjectOptions, cleanUp bool) error {
tgtRCFile := filepath.Join(outputDir, basename+".rc") tgtRCFile := filepath.Join(outputDir, basename+".rc")
if !b.fs.FileExists(tgtRCFile) { if !b.fs.FileExists(tgtRCFile) {
srcRCfile := filepath.Join(b.getPackageFileBaseDir(), "wails.rc") srcRCfile := filepath.Join(b.getPackageFileBaseDir(), "wails.rc")
rcfilebytes, err := ioutil.ReadFile(srcRCfile) rcfilebytes, err := os.ReadFile(srcRCfile)
if err != nil { if err != nil {
return err return err
} }
rcfiledata := strings.Replace(string(rcfilebytes), "$NAME$", basename, -1) rcfiledata := strings.Replace(string(rcfilebytes), "$NAME$", basename, -1)
err = ioutil.WriteFile(tgtRCFile, []byte(rcfiledata), 0755) err = os.WriteFile(tgtRCFile, []byte(rcfiledata), 0755)
if err != nil { if err != nil {
return err return err
} }
@ -387,11 +386,11 @@ func (b *PackageHelper) copyIcon() (string, error) {
// Install default icon // Install default icon
iconfile := filepath.Join(b.getPackageFileBaseDir(), "icon.png") iconfile := filepath.Join(b.getPackageFileBaseDir(), "icon.png")
iconData, err := ioutil.ReadFile(iconfile) iconData, err := os.ReadFile(iconfile)
if err != nil { if err != nil {
return "", err return "", err
} }
err = ioutil.WriteFile(srcIcon, iconData, 0644) err = os.WriteFile(srcIcon, iconData, 0644)
if err != nil { if err != nil {
return "", err return "", err
} }

View File

@ -3,7 +3,6 @@ package cmd
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"runtime" "runtime"
@ -310,14 +309,14 @@ func (po *ProjectOptions) WriteProjectConfig() error {
return err return err
} }
return ioutil.WriteFile(targetFile, filedata, 0600) return os.WriteFile(targetFile, filedata, 0600)
} }
// LoadConfig loads the project configuration file from the // LoadConfig loads the project configuration file from the
// given directory // given directory
func (po *ProjectOptions) LoadConfig(projectDir string) error { func (po *ProjectOptions) LoadConfig(projectDir string) error {
targetFile := filepath.Join(projectDir, "project.json") targetFile := filepath.Join(projectDir, "project.json")
rawBytes, err := ioutil.ReadFile(targetFile) rawBytes, err := os.ReadFile(targetFile)
if err != nil { if err != nil {
return err return err
} }

View File

@ -3,7 +3,6 @@ package cmd
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil"
"log" "log"
"os" "os"
"path/filepath" "path/filepath"
@ -124,7 +123,7 @@ func (s *SystemHelper) setup() error {
if err != nil { if err != nil {
return err return err
} }
err = ioutil.WriteFile(s.wailsSystemConfig, configData, 0755) err = os.WriteFile(s.wailsSystemConfig, configData, 0755)
if err != nil { if err != nil {
return err return err
} }
@ -207,11 +206,11 @@ func (sc *SystemConfig) Save(filename string) error {
} }
// Write it out to the config file // Write it out to the config file
return ioutil.WriteFile(filename, theJSON, 0644) return os.WriteFile(filename, theJSON, 0644)
} }
func (sc *SystemConfig) load(filename string) error { func (sc *SystemConfig) load(filename string) error {
configData, err := ioutil.ReadFile(filename) configData, err := os.ReadFile(filename)
if err != nil { if err != nil {
return err return err
} }

View File

@ -4,8 +4,8 @@ import (
"bytes" "bytes"
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil"
"log" "log"
"os"
"path/filepath" "path/filepath"
"runtime" "runtime"
"strings" "strings"
@ -125,7 +125,7 @@ func (t *TemplateHelper) LoadMetadata(dir string) (*TemplateMetadata, error) {
if !t.fs.FileExists(templateFile) { if !t.fs.FileExists(templateFile) {
return nil, nil return nil, nil
} }
rawJSON, err := ioutil.ReadFile(templateFile) rawJSON, err := os.ReadFile(templateFile)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -3,7 +3,6 @@ package main
import ( import (
"bufio" "bufio"
"fmt" "fmt"
"io/ioutil"
"log" "log"
"os" "os"
"path/filepath" "path/filepath"
@ -305,7 +304,7 @@ func updateWailsVersion(currentVersion, latestVersion *semver.Version) error {
new := fmt.Sprintf("%s v%s", wailsModule, latestVersion) new := fmt.Sprintf("%s v%s", wailsModule, latestVersion)
goMod = strings.Replace(goMod, old, new, -1) goMod = strings.Replace(goMod, old, new, -1)
err := ioutil.WriteFile(goModFile, []byte(goMod), 0600) err := os.WriteFile(goModFile, []byte(goMod), 0600)
if err != nil { if err != nil {
checkSpinner.Error() checkSpinner.Error()
return err return err
@ -343,7 +342,7 @@ func patchMainJS() error {
newStartLine := `Wails.Init` newStartLine := `Wails.Init`
mainJSContents = strings.Replace(mainJSContents, oldStartLine, newStartLine, -1) mainJSContents = strings.Replace(mainJSContents, oldStartLine, newStartLine, -1)
err := ioutil.WriteFile(mainJSFile, []byte(mainJSContents), 0600) err := os.WriteFile(mainJSFile, []byte(mainJSContents), 0600)
if err != nil { if err != nil {
checkSpinner.Error() checkSpinner.Error()
return err return err

View File

@ -2,7 +2,7 @@ package main
import ( import (
"fmt" "fmt"
"io/ioutil" "io"
"net/http" "net/http"
"net/url" "net/url"
"os" "os"
@ -112,7 +112,7 @@ To help you in this process, we will ask for some information, add Go/Wails deta
os.Exit(1) os.Exit(1)
} }
defer resp.Body.Close() defer resp.Body.Close()
template, _ := ioutil.ReadAll(resp.Body) template, _ := io.ReadAll(resp.Body)
body := string(template) body := string(template)
body = "**Description**\n" + (strings.Split(body, "**Description**")[1]) body = "**Description**\n" + (strings.Split(body, "**Description**")[1])
fullURL := "https://github.com/wailsapp/wails/issues/new?" fullURL := "https://github.com/wailsapp/wails/issues/new?"

View File

@ -2,7 +2,6 @@ package binding
import ( import (
"fmt" "fmt"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"reflect" "reflect"
@ -144,7 +143,7 @@ export {};`
dir := filepath.Dir(typescriptDefinitionFilename) dir := filepath.Dir(typescriptDefinitionFilename)
os.MkdirAll(dir, 0755) os.MkdirAll(dir, 0755)
return ioutil.WriteFile(typescriptDefinitionFilename, []byte(output.String()), 0755) return os.WriteFile(typescriptDefinitionFilename, []byte(output.String()), 0755)
} }
// bind the given struct method // bind the given struct method

View File

@ -4,15 +4,14 @@ import (
"embed" "embed"
"encoding/json" "encoding/json"
"fmt" "fmt"
"github.com/go-git/go-git/v5"
gofs "io/fs" gofs "io/fs"
"io/ioutil"
"log" "log"
"os" "os"
"path/filepath" "path/filepath"
"runtime" "runtime"
"strings" "strings"
"github.com/go-git/go-git/v5"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/leaanthony/debme" "github.com/leaanthony/debme"
@ -295,7 +294,7 @@ func Install(options *Options) (bool, *Template, error) {
// Clones the given uri and returns the temporary cloned directory // Clones the given uri and returns the temporary cloned directory
func gitclone(options *Options) (string, error) { func gitclone(options *Options) (string, error) {
// Create temporary directory // Create temporary directory
dirname, err := ioutil.TempDir("", "wails-template-*") dirname, err := os.MkdirTemp("", "wails-template-*")
if err != nil { if err != nil {
return "", err return "", err
} }

View File

@ -4,7 +4,6 @@ import (
"crypto/md5" "crypto/md5"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"runtime" "runtime"
@ -126,7 +125,7 @@ func RelativePath(relativepath string, optionalpaths ...string) string {
// MustLoadString attempts to load a string and will abort with a fatal message if // MustLoadString attempts to load a string and will abort with a fatal message if
// something goes wrong // something goes wrong
func MustLoadString(filename string) string { func MustLoadString(filename string) string {
data, err := ioutil.ReadFile(filename) data, err := os.ReadFile(filename)
if err != nil { if err != nil {
fmt.Printf("FATAL: Unable to load file '%s': %s\n", filename, err.Error()) fmt.Printf("FATAL: Unable to load file '%s': %s\n", filename, err.Error())
os.Exit(1) os.Exit(1)
@ -163,7 +162,7 @@ func MustMD5File(filename string) string {
// MustWriteString will attempt to write the given data to the given filename // MustWriteString will attempt to write the given data to the given filename
// It will abort the program in the event of a failure // It will abort the program in the event of a failure
func MustWriteString(filename string, data string) { func MustWriteString(filename string, data string) {
err := ioutil.WriteFile(filename, []byte(data), 0755) err := os.WriteFile(filename, []byte(data), 0755)
if err != nil { if err != nil {
fatal("Unable to write file", filename, ":", err.Error()) fatal("Unable to write file", filename, ":", err.Error())
os.Exit(1) os.Exit(1)
@ -244,7 +243,7 @@ func CopyDir(src string, dst string) (err error) {
return return
} }
entries, err := ioutil.ReadDir(src) entries, err := os.ReadDir(src)
if err != nil { if err != nil {
return return
} }
@ -260,7 +259,7 @@ func CopyDir(src string, dst string) (err error) {
} }
} else { } else {
// Skip symlinks. // Skip symlinks.
if entry.Mode()&os.ModeSymlink != 0 { if entry.Type()&os.ModeSymlink != 0 {
continue continue
} }
@ -306,7 +305,7 @@ func CopyDirExtended(src string, dst string, ignore []string) (err error) {
return return
} }
entries, err := ioutil.ReadDir(src) entries, err := os.ReadDir(src)
if err != nil { if err != nil {
return return
} }
@ -325,7 +324,7 @@ func CopyDirExtended(src string, dst string, ignore []string) (err error) {
} }
} else { } else {
// Skip symlinks. // Skip symlinks.
if entry.Mode()&os.ModeSymlink != 0 { if entry.Type()&os.ModeSymlink != 0 {
continue continue
} }
@ -370,7 +369,7 @@ func MoveDirExtended(src string, dst string, ignore []string) (err error) {
return return
} }
entries, err := ioutil.ReadDir(src) entries, err := os.ReadDir(src)
if err != nil { if err != nil {
return return
} }
@ -383,7 +382,7 @@ func MoveDirExtended(src string, dst string, ignore []string) (err error) {
dstPath := filepath.Join(dst, entry.Name()) dstPath := filepath.Join(dst, entry.Name())
// Skip symlinks. // Skip symlinks.
if entry.Mode()&os.ModeSymlink != 0 { if entry.Type()&os.ModeSymlink != 0 {
continue continue
} }

View File

@ -3,7 +3,7 @@ package github
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil" "io"
"net/http" "net/http"
"sort" "sort"
"strings" "strings"
@ -20,7 +20,7 @@ func GetVersionTags() ([]*SemanticVersion, error) {
if err != nil { if err != nil {
return result, err return result, err
} }
body, err := ioutil.ReadAll(resp.Body) body, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
return result, err return result, err
} }

View File

@ -2,9 +2,9 @@ package html
import ( import (
"fmt" "fmt"
"io/ioutil"
"log" "log"
"net/url" "net/url"
"os"
"path/filepath" "path/filepath"
"regexp" "regexp"
"strings" "strings"
@ -39,7 +39,7 @@ type Asset struct {
// Load the asset from disk // Load the asset from disk
func (a *Asset) Load(basedirectory string) error { func (a *Asset) Load(basedirectory string) error {
assetpath := filepath.Join(basedirectory, a.Path) assetpath := filepath.Join(basedirectory, a.Path)
data, err := ioutil.ReadFile(assetpath) data, err := os.ReadFile(assetpath)
if err != nil { if err != nil {
return err return err
} }

View File

@ -4,7 +4,7 @@ import (
"bytes" "bytes"
"fmt" "fmt"
"io" "io"
"io/ioutil" "os"
"path/filepath" "path/filepath"
"strings" "strings"
@ -189,7 +189,7 @@ func (a *AssetBundle) WriteToCFile(targetDir string) (string, error) {
// Save file // Save file
assetsFile := filepath.Join(targetDir, "assets.h") assetsFile := filepath.Join(targetDir, "assets.h")
err = ioutil.WriteFile(assetsFile, []byte(cdata.String()), 0600) err = os.WriteFile(assetsFile, []byte(cdata.String()), 0600)
if err != nil { if err != nil {
return "", err return "", err
} }

View File

@ -2,7 +2,6 @@ package project
import ( import (
"encoding/json" "encoding/json"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"runtime" "runtime"
@ -77,7 +76,7 @@ func Load(projectPath string) (*Project, error) {
// Attempt to load project.json // Attempt to load project.json
projectFile := filepath.Join(projectPath, "wails.json") projectFile := filepath.Join(projectPath, "wails.json")
rawBytes, err := ioutil.ReadFile(projectFile) rawBytes, err := os.ReadFile(projectFile)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -3,7 +3,6 @@ package main
import ( import (
"bytes" "bytes"
"fmt" "fmt"
"io/ioutil"
"log" "log"
"os" "os"
"strings" "strings"
@ -51,7 +50,7 @@ func main() {
} }
wailsJS := fs.RelativePath("../assets/desktop_" + platform + ".js") wailsJS := fs.RelativePath("../assets/desktop_" + platform + ".js")
runtimeData, err := ioutil.ReadFile(wailsJS) runtimeData, err := os.ReadFile(wailsJS)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
@ -78,7 +77,7 @@ const unsigned char runtime[]={`
// Save file // Save file
outputFile := fs.RelativePath(fmt.Sprintf("../../ffenestri/runtime_%s.c", platform)) outputFile := fs.RelativePath(fmt.Sprintf("../../ffenestri/runtime_%s.c", platform))
if err := ioutil.WriteFile(outputFile, []byte(runtimeC), 0600); err != nil { if err := os.WriteFile(outputFile, []byte(runtimeC), 0600); err != nil {
log.Fatal(err) log.Fatal(err)
} }
} }

View File

@ -5,7 +5,6 @@ package operatingsystem
import ( import (
"fmt" "fmt"
"io/ioutil"
"os" "os"
"strings" "strings"
) )
@ -17,7 +16,7 @@ func platformInfo() (*OS, error) {
return nil, fmt.Errorf("unable to read system information") return nil, fmt.Errorf("unable to read system information")
} }
osRelease, _ := ioutil.ReadFile("/etc/os-release") osRelease, _ := os.ReadFile("/etc/os-release")
return parseOsRelease(string(osRelease)), nil return parseOsRelease(string(osRelease)), nil
} }

View File

@ -3,7 +3,6 @@ package build
import ( import (
"bytes" "bytes"
"fmt" "fmt"
"io/ioutil"
"os" "os"
"os/exec" "os/exec"
"path/filepath" "path/filepath"
@ -87,7 +86,7 @@ func (b *BaseBuilder) buildCustomAssets(projectData *project.Project) error {
if len(localPath) == 0 { if len(localPath) == 0 {
return nil 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) assets.AddAsset(localPath, data)
} }
@ -100,7 +99,7 @@ func (b *BaseBuilder) buildCustomAssets(projectData *project.Project) error {
// Write assetdb out to root directory // Write assetdb out to root directory
assetsDbFilename := fs.RelativePath("../../../assetsdb.go") assetsDbFilename := fs.RelativePath("../../../assetsdb.go")
b.addFileToDelete(assetsDbFilename) 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 { if err != nil {
return err return err
} }
@ -108,7 +107,7 @@ func (b *BaseBuilder) buildCustomAssets(projectData *project.Project) error {
} }
func (b *BaseBuilder) convertFileToIntegerString(filename string) (string, error) { func (b *BaseBuilder) convertFileToIntegerString(filename string) (string, error) {
rawData, err := ioutil.ReadFile(filename) rawData, err := os.ReadFile(filename)
if err != nil { if err != nil {
return "", err return "", err
} }

View File

@ -2,12 +2,12 @@ package build
import ( import (
"fmt" "fmt"
"github.com/wailsapp/wails/v2/pkg/buildassets" "os"
"io/ioutil"
"path/filepath" "path/filepath"
"github.com/wailsapp/wails/v2/internal/fs" "github.com/wailsapp/wails/v2/internal/fs"
"github.com/wailsapp/wails/v2/internal/html" "github.com/wailsapp/wails/v2/internal/html"
"github.com/wailsapp/wails/v2/pkg/buildassets"
) )
// DesktopBuilder builds applications for the desktop // 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") wailsJS := fs.RelativePath("../../../internal/runtime/assets/desktop.js")
runtimeData, err := ioutil.ReadFile(wailsJS) runtimeData, err := os.ReadFile(wailsJS)
if err != nil { if err != nil {
return err return err
} }
@ -158,7 +158,7 @@ const unsigned char runtime[]={`
// Save file // Save file
outputFile := fs.RelativePath("../../../internal/ffenestri/runtime.c") 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 return err
} }

View File

@ -5,7 +5,6 @@ package build
import ( import (
"fmt" "fmt"
"io/ioutil"
"log" "log"
"path/filepath" "path/filepath"
"strconv" "strconv"
@ -75,7 +74,7 @@ func (d *DesktopBuilder) processTrayIcons(assetDir string, options *Options) err
for count, filename := range trayIconFilenames { for count, filename := range trayIconFilenames {
// Load the tray icon // Load the tray icon
dataBytes, err = ioutil.ReadFile(filename) dataBytes, err = os.ReadFile(filename)
if err != nil { if err != nil {
return err return err
} }
@ -110,7 +109,7 @@ func (d *DesktopBuilder) processTrayIcons(assetDir string, options *Options) err
} }
cdata.WriteString("0x00 };\n") cdata.WriteString("0x00 };\n")
err = ioutil.WriteFile(targetFile, []byte(cdata.String()), 0600) err = os.WriteFile(targetFile, []byte(cdata.String()), 0600)
if err != nil { if err != nil {
return err return err
} }
@ -169,7 +168,7 @@ func (d *DesktopBuilder) processDialogIcons(assetDir string, options *Options) e
for count, filename := range dialogIconFilenames { for count, filename := range dialogIconFilenames {
// Load the tray icon // Load the tray icon
dataBytes, err = ioutil.ReadFile(filename) dataBytes, err = os.ReadFile(filename)
if err != nil { if err != nil {
return err return err
} }
@ -204,7 +203,7 @@ func (d *DesktopBuilder) processDialogIcons(assetDir string, options *Options) e
} }
cdata.WriteString("0x00 };\n") cdata.WriteString("0x00 };\n")
err = ioutil.WriteFile(targetFile, []byte(cdata.String()), 0600) err = os.WriteFile(targetFile, []byte(cdata.String()), 0600)
if err != nil { if err != nil {
return err return err
} }

View File

@ -5,7 +5,6 @@ package build
import ( import (
"image/png" "image/png"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"strings" "strings"
@ -52,7 +51,7 @@ func (d *DesktopBuilder) compileIcon(assetDir string, iconFile string) error {
output = strings.Replace(output, "static char", "const char", 1) output = strings.Replace(output, "static char", "const char", 1)
// save icon.c // save icon.c
err = ioutil.WriteFile(targetFile, []byte(output), 0755) err = os.WriteFile(targetFile, []byte(output), 0755)
return err return err
} }

View File

@ -2,12 +2,13 @@ package main
import ( import (
"fmt" "fmt"
"github.com/leaanthony/slicer"
"io/ioutil"
"log" "log"
"os"
"path/filepath" "path/filepath"
"strconv" "strconv"
"strings" "strings"
"github.com/leaanthony/slicer"
) )
func convertToHexLiteral(bytes []byte) string { func convertToHexLiteral(bytes []byte) string {
@ -56,7 +57,7 @@ func buildMacIcons(dialogIconFilenames []string) error {
for count, filename := range dialogIconFilenames { for count, filename := range dialogIconFilenames {
// Load the tray icon // Load the tray icon
dataBytes, err = ioutil.ReadFile(filename) dataBytes, err = os.ReadFile(filename)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
@ -91,7 +92,7 @@ func buildMacIcons(dialogIconFilenames []string) error {
} }
cdata.WriteString("0x00 };\n") cdata.WriteString("0x00 };\n")
err = ioutil.WriteFile(targetFile, []byte(cdata.String()), 0600) err = os.WriteFile(targetFile, []byte(cdata.String()), 0600)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }

View File

@ -2,7 +2,6 @@ package build
import ( import (
"fmt" "fmt"
"io/ioutil"
"os" "os"
"strings" "strings"
@ -73,7 +72,7 @@ func (s *ServerBuilder) BuildBaseAssets(assets *html.AssetBundle) error {
// Add wails.js // Add wails.js
wailsjsPath := fs.RelativePath("../../../internal/runtime/assets/server.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) db.AddAsset("/wails.js", rawData)
} }

View File

@ -4,7 +4,7 @@ import (
"bytes" "bytes"
_ "embed" _ "embed"
"encoding/json" "encoding/json"
"io/ioutil" "io"
"log" "log"
"net/http" "net/http"
"os" "os"
@ -44,7 +44,7 @@ func main() {
log.Fatal(err) log.Fatal(err)
} }
defer resp.Body.Close() defer resp.Body.Close()
data, err := ioutil.ReadAll(resp.Body) data, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }

View File

@ -3,7 +3,6 @@ package parser
import ( import (
"bytes" "bytes"
_ "embed" _ "embed"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"text/template" "text/template"
@ -135,7 +134,7 @@ func generatePackage(pkg *Package, moduledir string) error {
} }
// Save typescript file // 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 { if err != nil {
return errors.Wrap(err, "Error writing backend package file") return errors.Wrap(err, "Error writing backend package file")
} }
@ -156,7 +155,7 @@ func generatePackage(pkg *Package, moduledir string) error {
} }
// Save javascript file // 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 { if err != nil {
return errors.Wrap(err, "Error writing backend package file") return errors.Wrap(err, "Error writing backend package file")
} }
@ -183,7 +182,7 @@ func generateIndexJS(dir string, packages []*Package) error {
// Calculate target filename // Calculate target filename
indexJS := filepath.Join(dir, "index.js") indexJS := filepath.Join(dir, "index.js")
err = ioutil.WriteFile(indexJS, buffer.Bytes(), 0755) err = os.WriteFile(indexJS, buffer.Bytes(), 0755)
if err != nil { if err != nil {
return errors.Wrap(err, "Error writing backend package index.js file") 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 // Calculate target filename
indexJS := filepath.Join(dir, "index.d.ts") indexJS := filepath.Join(dir, "index.d.ts")
err = ioutil.WriteFile(indexJS, buffer.Bytes(), 0755) err = os.WriteFile(indexJS, buffer.Bytes(), 0755)
if err != nil { if err != nil {
return errors.Wrap(err, "Error writing backend package index.d.ts file") 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 // Calculate target filename
indexJS := filepath.Join(dir, "globals.d.ts") indexJS := filepath.Join(dir, "globals.d.ts")
err = ioutil.WriteFile(indexJS, buffer.Bytes(), 0755) err = os.WriteFile(indexJS, buffer.Bytes(), 0755)
if err != nil { if err != nil {
return errors.Wrap(err, "Error writing backend package globals.d.ts file") return errors.Wrap(err, "Error writing backend package globals.d.ts file")
} }