Skip to content

Latest commit

 

History

History
71 lines (52 loc) · 1.07 KB

02-hello-go.md

File metadata and controls

71 lines (52 loc) · 1.07 KB

02-hello-go

Create a new project with source code

mkdir 02-hello-go
cd 02-hello-go
go mod init hello-go
touch main.go
package main

import (
	"fmt"
	"os" 
)

func main() {

	fmt.Println("👋 Hello World from Go 🌍")
	args := os.Args
	argsWithoutCaller := os.Args[1:]

	fmt.Println(args)
	fmt.Println(argsWithoutCaller)

}

Build

tinygo build -o main.wasm -target wasi ./main.go

ls -lh *.wasm

Run

wasmtime main.wasm hello world
wasmedge main.wasm hello world
wazero run main.wasm hello world

Change the source code

of the main function

// Create a new scanner to read from standard input
scanner := bufio.NewScanner(os.Stdin)

fmt.Println("Enter some text (press Ctrl+D or Ctrl+Z to end):")

// Read input line by line
for scanner.Scan() {
    text := scanner.Text() // Get the current line of text
    if text == "" {
        break // Exit loop if an empty line is entered
    }
    fmt.Println("You entered:", text)
}

if err := scanner.Err(); err != nil {
    fmt.Println("Error:", err)
}

Re-build and re-run