-
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
3 changed files
with
44 additions
and
100 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,103 +1,47 @@ | ||
// //go:generate tinygo build -o main.wasm -target=wasi -scheduler=none main.go | ||
//go:generate tinygo build -o main.wasm -target=wasi -scheduler=none main.go | ||
|
||
package main | ||
|
||
// import ( | ||
// "bytes" | ||
// "context" | ||
// "io" | ||
// "log/slog" | ||
// "os" | ||
|
||
// "capnproto.org/go/capnp/v3" | ||
// "github.com/urfave/cli/v2" | ||
// "github.com/wetware/go/proc" | ||
// ) | ||
|
||
// func main() { | ||
// ctx := context.TODO() | ||
|
||
// app := &cli.App{ | ||
// Name: "deliver", | ||
// Usage: "read message from stdn and send to `PID`", | ||
// ArgsUsage: "<PID>", | ||
// Flags: []cli.Flag{ | ||
// &cli.StringFlag{ | ||
// Name: "method", | ||
// Aliases: []string{"m"}, | ||
// Usage: "method name", | ||
// }, | ||
// &cli.Uint64SliceFlag{ | ||
// Name: "push", | ||
// Aliases: []string{"p"}, | ||
// Usage: "push u64 onto stack", | ||
// }, | ||
// }, | ||
// 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() | ||
|
||
// m, seg := capnp.NewSingleSegmentMessage(nil) | ||
// defer m.Release() | ||
|
||
// call, err := proc.NewRootMethodCall(seg) | ||
// if err != nil { | ||
// return err | ||
// } | ||
|
||
// err = call.SetName(c.String("method")) | ||
// if err != nil { | ||
// return err | ||
// } | ||
|
||
// stack := c.Uint64Slice("stack") | ||
// size := int32(len(stack)) | ||
|
||
// callStack, err := call.NewStack(size) | ||
// if err != nil { | ||
// return err | ||
// } | ||
|
||
// for i, word := range stack { | ||
// callStack.Set(i, word) | ||
// } | ||
|
||
// r := io.LimitReader(c.App.Reader, 1<<32-1) // max u32 | ||
// data, err := io.ReadAll(r) | ||
// if err != nil { | ||
// return err | ||
// } | ||
|
||
// if err = call.SetCallData(data); err != nil { | ||
// return err | ||
// } | ||
|
||
// b, err := m.Marshal() | ||
// if err != nil { | ||
// return err | ||
// } | ||
|
||
// n, err := io.Copy(f, bytes.NewReader(b)) | ||
// if err != nil { | ||
// return err | ||
// } | ||
|
||
// slog.DebugContext(c.Context, "delivered message", | ||
// "size", n, | ||
// "dest", name) | ||
// return nil | ||
// } | ||
import ( | ||
"fmt" | ||
"io" | ||
"log/slog" | ||
"os" | ||
) | ||
|
||
func main() { | ||
if len(os.Args) < 1 { | ||
slog.Error("expected 1 argument, got 0", | ||
"status", 1) | ||
os.Exit(1) | ||
} | ||
|
||
f, err := os.Open(os.Args[0]) | ||
if err != nil { | ||
slog.Error("failed to open file", | ||
"reason", err, | ||
"status", 2, | ||
"name", os.Args[0]) | ||
os.Exit(2) | ||
} | ||
defer f.Close() | ||
|
||
var n int64 | ||
var status int | ||
if n, err = io.Copy(f, os.Stdin); err != nil { | ||
status = 3 | ||
err = fmt.Errorf("request: %w", err) | ||
} else if n, err = io.Copy(os.Stdout, f); err != nil { | ||
status = 4 | ||
err = fmt.Errorf("response: %w", err) | ||
} | ||
|
||
if err != nil { | ||
slog.Error("failed to read message from stdin", | ||
"reason", err, | ||
"status", status, | ||
"read", n) | ||
} | ||
|
||
os.Exit(status) | ||
} |
Binary file not shown.
Binary file not shown.