Skip to content

Commit

Permalink
cleanup on formatJSON func
Browse files Browse the repository at this point in the history
  • Loading branch information
fantasticrabbit committed Nov 14, 2021
1 parent 9e8ec07 commit df079a5
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 14 deletions.
2 changes: 1 addition & 1 deletion cmd/getlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var listCmd = &cobra.Command{
ListID: string(args[0]),
Subtasks: viper.GetBool("subtasks"),
}
fmt.Println(string(l.GetJSON(l.BuildPath())))
fmt.Println(internal.FormatJSON(l.GetJSON(l.BuildPath())))
},
}

Expand Down
8 changes: 2 additions & 6 deletions cmd/gettask.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package cmd
import (
"errors"
"fmt"
"log"
"strings"

"github.com/fantasticrabbit/ClickupCLI/internal"
Expand Down Expand Up @@ -34,11 +33,8 @@ var taskCmd = &cobra.Command{
TeamID: viper.GetString("team"),
Subtasks: viper.GetBool("subtasks"),
}
x, err := internal.FormatJSON(string(t.GetJSON(t.BuildPath())))
if err != nil {
log.Fatalln(err)
}
fmt.Println(x, err)

fmt.Println(internal.FormatJSON(t.GetJSON(t.BuildPath())))
},
}

Expand Down
2 changes: 1 addition & 1 deletion internal/getlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,6 @@ func (l ListRequest) BuildPath() string {
}

//GetJSON accepts an API path and returns byte payload of JSON data
func (t ListRequest) GetJSON(apiPath string) []byte {
func (t ListRequest) GetJSON(apiPath string) string {
return getJSON(apiPath)
}
2 changes: 1 addition & 1 deletion internal/gettask.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ func (t TaskRequest) BuildPath() string {
}

//GetJSON accepts an API path and returns byte payload of JSON data
func (t TaskRequest) GetJSON(apiPath string) []byte {
func (t TaskRequest) GetJSON(apiPath string) string {
return getJSON(apiPath)
}
10 changes: 5 additions & 5 deletions internal/requester.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func init() {
}

//Gets JSON data for any struct that implements Requester interface
func getJSON(apiPath string) []byte {
func getJSON(apiPath string) string {
req, _ := http.NewRequest(http.MethodGet, apiPath, nil)
req.Header.Add("Authorization", viper.GetString("token"))
req.Header.Add("Content-Type", "application/json")
Expand All @@ -40,13 +40,13 @@ func getJSON(apiPath string) []byte {
}
defer resp.Body.Close()
resp_body, _ := ioutil.ReadAll(resp.Body)
return resp_body
return string(resp_body)
}

func FormatJSON(str string) (string, error) {
func FormatJSON(str string) string {
var formattedJSON bytes.Buffer
if err := json.Indent(&formattedJSON, []byte(str), "", " "); err != nil {
return "", err
log.Fatalln(err)
}
return formattedJSON.String(), nil
return formattedJSON.String()
}

0 comments on commit df079a5

Please sign in to comment.