From bcdc3f7dfb0614148c16e627a1b1e280a72e16cf Mon Sep 17 00:00:00 2001 From: Ernesto ponce Date: Tue, 13 Feb 2024 18:13:01 -0300 Subject: [PATCH] add option to send message to server from file --- README.md | 7 ++++++- main.go | 14 ++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c21ac6f..a3a3c51 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,11 @@ Send query to graphql server ```bash req -t gq -u https://countries.trevorblades.com/ -p 'query {countries {name}}' ``` +Use file to send query +```bash +req -t gq -u https://countries.trevorblades.com/ -p @myfolder/query.txt +``` + ### GRPC @@ -72,7 +77,7 @@ req -t grpc -u localhost:50051 -import-path /pathprotofiles/helloworld -proto he | --- | --- | | -u | url server | | -m | http method | -| -p | data to send to server | +| -p | data to send to server in raw string of use @myfolder/file to send from file | | -t | type protocol (http, ws, gq, grpc) defaut http | | -q | http query params | | -h | http headers | diff --git a/main.go b/main.go index 990f06b..b05309d 100644 --- a/main.go +++ b/main.go @@ -74,6 +74,20 @@ func main() { download := flag.Bool("d", false, "download content") flag.Parse() + if len(params.message) > 0 { + atSymbol := 64 + if params.message[0] == byte(atSymbol) { + filePath := string(params.message[1:]) + + content, err := os.ReadFile(filePath) + if err != nil { + fmt.Println(styleErr.Render("Error reading file: " + err.Error())) + return + } + params.message = string(content) + } + } + validProtocos := []string{"ws", "gq", "http", "grpc"} valid := false