Write and read into a file
mkdir 03-files-go
cd 03-files-go
go mod init files-go
touch main.go
package main
import (
"fmt"
"os"
)
func main() {
file, err := os.Create("hello.txt")
if err != nil {
fmt.Println("😡", err)
return
}
defer file.Close()
_, err = file.WriteString("👋 Hello, World! 🌍")
if err != nil {
fmt.Println("😡", err)
return
}
data, err := os.ReadFile("hello.txt")
if err != nil {
fmt.Println("😡", err)
}
fmt.Print(string(data))
}
tinygo build -o main.wasm -target wasi ./main.go
ls -lh *.wasm
wasmedge main.wasm
Yous should get an error
Read this to fix it: https://wasmedge.org/docs/start/build-and-run/cli/