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

Commit

Permalink
⚒Minor Refactors
Browse files Browse the repository at this point in the history
  • Loading branch information
athul committed Jan 24, 2020
1 parent 8d552a5 commit 1894fbf
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 14 deletions.
2 changes: 1 addition & 1 deletion cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func main() {
Usage: "Send a GET request",
Flags: getFlags,
Action: func(c *cli.Context) error {
mets.Basicreq(c)
mets.Getbasic(c)
return nil
},
},
Expand Down
2 changes: 1 addition & 1 deletion methods/fns.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

// Formatresp formats the Response with Indents and Colors
func Formatresp(resp *http.Response) string {
func formatresp(resp *http.Response) string {
body, err := ioutil.ReadAll(resp.Body)
str := string(body)
var obj map[string]interface{}
Expand Down
11 changes: 4 additions & 7 deletions methods/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"github.com/urfave/cli"
)

//Basicreq sends a simple GET request to the url with any potential parameters like Tokens or Basic Auth
func Basicreq(c *cli.Context) error {
//Getbasic sends a simple GET request to the url with any potential parameters like Tokens or Basic Auth
func Getbasic(c *cli.Context) error {
var url = c.String("url")
req, err := http.NewRequest("GET", url, nil)
if err != nil {
Expand All @@ -24,16 +24,13 @@ func Basicreq(c *cli.Context) error {
pw := c.String("p")
req.Header.Add("Authorization", "Basic "+basicAuth(un, pw))
}
fmt.Print(req.Header)
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
log.Println("Error on response.\n[ERRO] -", err)
}
defer resp.Body.Close()
s := Formatresp(resp)
//log.Println()
fmt.Print(resp)
fmt.Printf("\n\n %s", s)
s := formatresp(resp)
fmt.Printf("\n%s", s)
return nil
}
6 changes: 1 addition & 5 deletions methods/post.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,12 @@ func Postbasic(c *cli.Context) {
pw := c.String("p")
req.Header.Add("Authorization", "Basic "+basicAuth(un, pw))
}
fmt.Print(req.Header)
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
s := Formatresp(resp)
fmt.Println("response Status:", resp.Status)
fmt.Println("response Headers:", resp.Header)
//body, _ := ioutil.ReadAll(resp.Body)
s := formatresp(resp)
fmt.Println("response Body:", s)
}

0 comments on commit 1894fbf

Please sign in to comment.