-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
1,132 additions
and
451 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
//go:generate tinygo build -o main.wasm -target=wasi -scheduler=none main.go | ||
|
||
package main | ||
|
||
import ( | ||
"context" | ||
"io" | ||
"log/slog" | ||
"os" | ||
|
||
"github.com/urfave/cli/v2" | ||
) | ||
|
||
func main() { | ||
ctx := context.TODO() | ||
|
||
app := &cli.App{ | ||
Name: "deliver", | ||
Usage: "read message from stdn and send to `PID`", | ||
ArgsUsage: "<PID>", | ||
// Flags: []cli.Flag{}, | ||
Action: deliver, | ||
} | ||
|
||
if err := app.RunContext(ctx, os.Args); err != nil { | ||
slog.ErrorContext(ctx, "application failed", | ||
"reason", err) | ||
os.Exit(1) | ||
} | ||
} | ||
|
||
func deliver(c *cli.Context) error { | ||
name := c.Args().First() | ||
f, err := os.Open(name) | ||
if err != nil { | ||
return err | ||
} | ||
defer f.Close() | ||
|
||
r := io.LimitReader(c.App.Reader, 1<<32-1) // max unit32 | ||
|
||
if n, err := io.Copy(f, r); err != nil { | ||
return err | ||
} else { | ||
slog.DebugContext(c.Context, "delivered message", | ||
"size", n, | ||
"dest", name) | ||
} | ||
|
||
return nil | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
//go:generate tinygo build -o main.wasm -target=wasi -scheduler=none main.go | ||
|
||
package main | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"os" | ||
) | ||
|
||
//export environment | ||
func environment(size uint32) { | ||
// Defensive: clear out any data that the user may have sent, | ||
// even if we aren't expecting it. | ||
defer io.Copy(io.Discard, os.Stdin) | ||
|
||
// Calmly print the environment to stdout | ||
for _, v := range os.Environ() { | ||
fmt.Fprintln(os.Stdout, v) | ||
} | ||
} | ||
|
||
func main() {} |
Binary file not shown.
Oops, something went wrong.