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

Commit

Permalink
📝Formatted the Repsonse
Browse files Browse the repository at this point in the history
  • Loading branch information
athul committed Jan 25, 2020
1 parent 4badcac commit a82e580
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.13

require (
github.com/TylerBrock/colorjson v0.0.0-20180527164720-95ec53f28296
github.com/fatih/color v1.9.0 // indirect
github.com/fatih/color v1.9.0
github.com/hokaccha/go-prettyjson v0.0.0-20190818114111-108c894c2c0e // indirect
github.com/urfave/cli v1.22.2
)
6 changes: 6 additions & 0 deletions methods/fns.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,29 @@ import (
"net/http"

"github.com/TylerBrock/colorjson"
"github.com/fatih/color"
)

// Formatresp formats the Response with Indents and Colors
func formatresp(resp *http.Response) string {
c := color.New(color.FgCyan)
body, err := ioutil.ReadAll(resp.Body)
str := string(body)
var obj map[string]interface{}
json.Unmarshal([]byte(str), &obj)
f := colorjson.NewFormatter()
f.Indent = 6
s, _ := f.Marshal(obj)
for key, value := range resp.Header {
c.Print(key, " : ", value, "\n")
}
retbody := fmt.Sprintf("\nStatus:\t\t%s\n\nStatusCode:\t%d\n\n%s\n", resp.Status, resp.StatusCode, string(s))
if err != nil {
log.Println("Error on response.\n[ERRO] -", err)
}
return retbody
}

func basicAuth(username, password string) string {
auth := username + ":" + password
return base64.StdEncoding.EncodeToString([]byte(auth))
Expand Down

0 comments on commit a82e580

Please sign in to comment.