Documentation
¶
Overview ¶
Package input builds HTTP request bodies from CLI arguments and/or stdin.
Index ¶
Constants ¶
View Source
const MaxStdinBodyBytes = 16 << 20
Variables ¶
This section is empty.
Functions ¶
func Body ¶
func Body(stdinReader io.Reader, stdinIsTTY bool, args []string, contentType string, bodyOpts BodyOptions) (any, error)
Body parses positional CLI args (shorthand syntax) and/or stdin into a request body. The rules are:
- No args, stdin is a TTY → nil body (no Content-Type sent).
- No args, data on stdin → parsed as shorthand/JSON/YAML and returned as a Go value so the content registry can marshal it correctly.
- Args only → joined with spaces (matches how the shell splits tokens) and parsed as shorthand.
- Stdin + args → stdin document is the base; args are applied as a shorthand patch on top.
The returned body is a Go value (map/slice/scalar) ready to be marshalled by the content registry, or nil if there is no body. stdinReader is cli.Stdin; pass strings.NewReader("") with stdinIsTTY=true in tests to simulate an empty terminal.
Types ¶
type BodyOptions ¶
BodyOptions controls request-body parsing.
Click to show internal directories.
Click to hide internal directories.