Skip to content
This repository has been archived by the owner on Jul 14, 2022. It is now read-only.

Commit

Permalink
🛠 Headers print in a single loop
Browse files Browse the repository at this point in the history
  • Loading branch information
athul committed Feb 13, 2020
1 parent bd19b81 commit 426c416
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
2 changes: 1 addition & 1 deletion cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ func main() {
{
Name: "send",
Usage: "Test all the Endpoints in the Postwoman Collection.json",
//Flags: sendFlag,
Action: func(c *cli.Context) error {
return mets.ReadCollection(c)
},
Expand All @@ -108,6 +107,7 @@ func main() {
WE REALLY NEED YOUR FEEDBACK,
CREATE A NEW ISSUE FOR BUGS AND FEATURE REQUESTS : < http://github.com/athul/pwcli >
`, cli.AppHelpTemplate)

err := app.Run(os.Args)
Expand Down
20 changes: 7 additions & 13 deletions methods/fns.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,34 +16,28 @@ import (
func formatresp(resp *http.Response) (string, error) {
var retbody string
heads := fmt.Sprint(resp.Header)
c := color.New(color.FgCyan, color.Bold)
c := color.New(color.FgHiCyan)
magenta := color.New(color.FgHiMagenta)
yellow := color.New(color.FgHiYellow)

body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return "", fmt.Errorf("Error reading response body: %s", err.Error())
}

for key, value := range resp.Header {
c.Print(key, " : ")
magenta.Print(value, "\n")
}
str := string(body)
if strings.Contains(heads, "json") {
for key, value := range resp.Header {
c.Print(key, " : ")
magenta.Print(value, "\n")
}
retbody = yellow.Sprintf("\nStatus:\t\t%s\n\nStatusCode:\t%d\n", resp.Status, resp.StatusCode) + fmt.Sprintf("\n%s\n", string(pretty.Color(pretty.Pretty(body), nil)))
retbody = color.HiYellowString("\nStatus:\t\t%s\n\nStatusCode:\t%d\n", resp.Status, resp.StatusCode) + fmt.Sprintf("\n%s\n", string(pretty.Color(pretty.Pretty(body), nil)))
} else if strings.Contains(heads, "xml") || strings.Contains(heads, "html") || strings.Contains(heads, "plain") {
for key, value := range resp.Header {
c.Print(key, " : ")
magenta.Print(value, "\n")
}
var s string
if strings.Contains(heads, "plain") {
s = str
} else {
s = c.Sprint(gohtml.Format(str))
}
retbody = yellow.Sprintf("\nStatus:\t\t%s\n\nStatusCode:\t%d\n", resp.Status, resp.StatusCode) + fmt.Sprintf("\n%s\n", s)
retbody = color.HiYellowString("\nStatus:\t\t%s\n\nStatusCode:\t%d\n", resp.Status, resp.StatusCode) + fmt.Sprintf("\n%s\n", s)
}
return retbody, nil
}
Expand Down

0 comments on commit 426c416

Please sign in to comment.