fullstorydev / fullstorydev/grpcurl
Support file input for request contents
- Dominant language
- Go
- Stars
- 12.8k
- Forks
- 580
- Avg merge
- 1h 8m
- Merged PRs (30d)
- 5
Description
Currently, grpcurl accept data input with `-d string` option.
We can set request content directly to `string` part.
If the value is '@', request contents are read from stdin.
So, we can set request content like this
```
grpcurl -d "{\"name\":\"sample user\"}" -proto ./helloworld.proto localhost:50051 sample.Greeter/SayHello
or
grpcurl -d @ -proto ./helloworld.proto localhost:50051 sample.Greeter/SayHello < {"name":"sample user"}
> EOM
or
grpcurl -d @ -proto ./helloworld.proto localhost:50051 sample.Greeter/SayHello < request_content.json
```
In this format, we have to keep options and file paths in different variables when writing some jobs in shell script.
For example,
```
#!/bin/bash
options_array=()
options_array+=("-H 'name1: value1' -d @")
options_array+=("-H 'name2: value2' -d @")
options_array+=("-H 'name3: value3' -d @")
options_array+=("-H 'name4: value4' -d @")
options_array+=("-H 'name5: value5' -d @")
contents_array=()
contents_array+=("request_content1.json")
contents_array+=("request_content2.json")
contents_array+=("request_content3.json")
contents_array+=("request_content4.json")
contents_array+=("request_content5.json")
for ((i=0; i<"${#options_array[@]}"; i++)); do
grpcurl ${options_array[${i}]} -proto ./helloworld.proto localhost:50051 sample.Greeter/SayHello < ${contents_array[${i}]}
done
```
So, I think the following format is better.
This format is the same as `curl` command (https://man7.org/linux/man-pages/man1/curl.1.html)
```
grpcurl -d "{\"name\":\"sample user\"}" -proto ./helloworld.proto localhost:50051 sample.Greeter/SayHello
or
// get contents from stdin with '@' or '@-' (curl command's style)
grpcurl -d @- -proto ./helloworld.proto localhost:50051 sample.Greeter/SayHello < {"name":"sample user"}
> EOM
or
// file paths can be set just after '@'
grpcurl -d @request_content.json -proto ./helloworld.proto localhost:50051 sample.Greeter/SayHello
```
Then, we can write the same logic shown above simply.
```
#!/bin/bash
options_array=()
options_array+=("-H 'name1: value1' -d @request_content1.json")
options_array+=("-H 'name2: value2' -d @request_content2.json")
options_array+=("-H 'name3: value3' -d @request_content3.json")
options_array+=("-H 'name4: value4' -d @request_content4.json")
options_array+=("-H 'name5: value5' -d @request_content5.json")
for option in "${options_array[@]}"; do
grpcurl ${option} -proto ./helloworld.proto localhost:50051 sample.Greeter/SayHello
done
```
Contributor guide
No contributing guide indexed for this repository
Research direction
No source files or tests are named. Start by tracing command-line handling for the -d option and its existing stdin behavior, then determine where an @- value or @file value is interpreted. Done means request contents can be read from stdin or the named file while preserving direct string input and the documented shell usage.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- cli
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100