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

Commit

Permalink
Removed Defer
Browse files Browse the repository at this point in the history
  • Loading branch information
athul committed Feb 3, 2020
1 parent a303eff commit b429674
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 22 deletions.
8 changes: 8 additions & 0 deletions cli.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"fmt"
"log"
"os"

Expand Down Expand Up @@ -128,6 +129,13 @@ func main() {
},
},
}
cli.AppHelpTemplate = fmt.Sprintf(`%sS
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)
if err != nil {
log.Fatal(err)
Expand Down
2 changes: 1 addition & 1 deletion methods/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func Deletebasic(c *cli.Context) {
if err != nil {
panic(err)
}
defer resp.Body.Close()
//defer resp.Body.Close()
s := formatresp(resp)
fmt.Println(s)
}
2 changes: 1 addition & 1 deletion methods/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func Getbasic(c *cli.Context) error {
if err != nil {
log.Println("Error on response.\n[ERRO] -", err)
}
defer resp.Body.Close()

s := formatresp(resp)
fmt.Println(s)
return nil
Expand Down
2 changes: 1 addition & 1 deletion methods/patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func Patchbasic(c *cli.Context) {
if err != nil {
panic(err)
}
defer resp.Body.Close()
//defer resp.Body.Close()
s := formatresp(resp)
fmt.Println(s)
}
2 changes: 1 addition & 1 deletion methods/post.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func Postbasic(c *cli.Context) {
if err != nil {
panic(err)
}
defer resp.Body.Close()
//defer resp.Body.Close()
s := formatresp(resp)
fmt.Println(s)
}
3 changes: 1 addition & 2 deletions methods/put.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ func Putbasic(c *cli.Context) {
if err != nil {
panic(err)
}
defer resp.Body.Close()

//defer resp.Body.Close()
s := formatresp(resp)
fmt.Println(s)
}
29 changes: 13 additions & 16 deletions methods/json.go → methods/send.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/urfave/cli"
)

//Colls hold the format of the basic `postwoman-collection.json`
//Colls hold the structure of the basic `postwoman-collection.json`
type Colls struct {
Name string `json:"name"`
Folders []string `json:"folders"`
Expand All @@ -29,6 +29,7 @@ type Reqdata struct {
Pass string `json:"httpPassword"`
Token string `json:"bearerToken"`
Ctype string `json:"contentType"`
Name string `json:"name"`
Heads []string `json:"headers"`
Params []string `json:"params"`
Bparams []Bpardata `json:"bodyParams"`
Expand All @@ -46,21 +47,13 @@ func ReadCollection(c *cli.Context) {
if err != nil {
fmt.Print(err)
}
//fmt.Print(string(data))
jsondat := []Colls{}

var jsondat []Colls
err = json.Unmarshal([]byte(data), &jsondat)
if err != nil {
fmt.Println(err)
}
fmt.Println("Name:\t" + color.HiMagentaString(jsondat[0].Name))
for i := 0; i < len(jsondat[0].Request); i++ {
/* fmt.Printf(`
URL: %s
Method: %s
Auth: %s
Token:%s
Headers: %s
-------`, jsondat[0].Request[i].URL+jsondat[0].Request[i].Path, jsondat[0].Request[i].Method, jsondat[0].Request[i].Auth, jsondat[0].Request[i].Token, jsondat[0].Request[i].Heads) */
request(jsondat, i)
}

Expand All @@ -82,7 +75,7 @@ func request(c []Colls, i int) {
}
methods := color.HiYellowString(c[0].Request[i].Method)
fURL := colors.Sprintf(c[0].Request[i].URL + c[0].Request[i].Path)
fmt.Printf("%s \t%s\t%s", fURL, methods, out)
fmt.Printf("%s |\t%s |\t%s |\t%s", color.HiGreenString(c[0].Request[i].Name), fURL, methods, out)
}

}
Expand All @@ -107,17 +100,21 @@ func getsend(c []Colls, ind int, method string) (string, error) {
if err != nil {
log.Println("Error on response.\n[ERRO] -", err)
}
defer resp.Body.Close()
//defer resp.Body.Close()
//fmt.Print(resp.Header)
s := color.Sprintf("Status: %s\tStatusCode:\t%d\n", resp.Status, resp.StatusCode)
return s, nil
}

func sendpopa(c []Colls, ind int, method string) (string, error) {
color := color.New(color.FgCyan, color.Bold)

var jsonStr []byte
var url = c[0].Request[ind].URL + c[0].Request[ind].Path
var jsonStr = []byte(string(c[0].Request[ind].Bparams[0].Key[0] + c[0].Request[ind].Bparams[0].Value[0]))
if len(c[0].Request[ind].Bparams) > 0 {
jsonStr = []byte(string(c[0].Request[ind].Bparams[0].Key[0] + c[0].Request[ind].Bparams[0].Value[0]))
} else {
jsonStr = nil
}

req, err := http.NewRequest(method, url, bytes.NewBuffer(jsonStr))
req.Header.Set("Content-Type", c[0].Request[ind].Ctype)
Expand All @@ -138,7 +135,7 @@ func sendpopa(c []Colls, ind int, method string) (string, error) {
if err != nil {
log.Println("Error on response.\n[ERRO] -", err)
}
defer resp.Body.Close()
//defer resp.Body.Close()
//fmt.Print(resp.Header)
s := color.Sprintf("Status: %s\tStatusCode:\t%d\n", resp.Status, resp.StatusCode)
return s, nil
Expand Down

0 comments on commit b429674

Please sign in to comment.