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

Commit

Permalink
Removed bauth command
Browse files Browse the repository at this point in the history
  • Loading branch information
athul committed Jan 22, 2020
1 parent 3a2b8c7 commit 997a8f0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 23 deletions.
22 changes: 4 additions & 18 deletions cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,6 @@ func main() {
Value: "Bearer Token",
Usage: "Send the Request with Bearer Token",
},
}
bauthFlags := []cli.Flag{
cli.StringFlag{
Name: "url",
Value: "https://reqres.in/api/users",
Usage: "The URL/Endpoint you want to check",
Required: true,
},
cli.StringFlag{
Name: "u",
Value: "Username",
Expand All @@ -46,29 +38,23 @@ func main() {
Required: true,
},
}

app.Commands = []cli.Command{
{
Name: "get",
Usage: "Send a GET request",
Flags: myFlags,
Action: func(c *cli.Context) error {
if c.String("token") != "" {
if c.String("u") != "" && c.String("p") != "" {
mets.Getbasic(c)
} else if c.String("token") != "" {
mets.Getwtoken(c)
} else {
mets.Getreq(c)
}
return nil
},
},
{
Name: "bauth",
Usage: "Send GET Request with Basic Auth(Don't Use get command with this)",
Flags: bauthFlags,
Action: func(c *cli.Context) error {
mets.Getbasic(c)
return nil
},
},
}
err := app.Run(os.Args)
if err != nil {
Expand Down
12 changes: 7 additions & 5 deletions methods/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
//Getreq sends a simple GET request to the url
func Getreq(c *cli.Context) error {
var url = c.String("url")

req, err := http.NewRequest("GET", url, nil)
if err != nil {
return err
Expand Down Expand Up @@ -44,9 +43,11 @@ func Getwtoken(c *cli.Context) error {
}
defer resp.Body.Close()
s := Formatresp(resp)
fmt.Print(resp)
fmt.Printf("\n\n %s", s)

if s != "" {
fmt.Printf("%s", s)
} else {
fmt.Print(resp)
}
return nil
}

Expand All @@ -62,9 +63,10 @@ func Getbasic(c *cli.Context) error {
if err != nil {
log.Println("Error on response.\n[ERRO] -", err)
}
defer resp.Body.Close()
s := Formatresp(resp)
if s != "" {
fmt.Printf("\n\n %s", s)
fmt.Printf("%s", s)
} else {
fmt.Print(resp)
}
Expand Down

0 comments on commit 997a8f0

Please sign in to comment.