Skip to content

Commit

Permalink
feat: add protocol into output
Browse files Browse the repository at this point in the history
  • Loading branch information
eynopv committed May 25, 2024
1 parent 2c9b96b commit a1a949f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
1 change: 1 addition & 0 deletions internal/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ func (c *Client) Do(r *request.Request) (*result.Result, error) {
res.Status,
res.StatusCode,
res.Header,
res.Proto,
body,
)

Expand Down
1 change: 1 addition & 0 deletions internal/request/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ func DoRequest(request *http.Request, timeout int) (*result.Result, error) {
res.Status,
res.StatusCode,
res.Header,
res.Proto,
body,
)

Expand Down
11 changes: 8 additions & 3 deletions internal/result/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type Result struct {
Path string
Status string
StatusCode int
Protocol string
ElapsedTime time.Duration
Body map[string]interface{}
Text string
Expand All @@ -26,6 +27,7 @@ func NewResult(
status string,
statusCode int,
headers http.Header,
protocol string,
bodyRaw []byte,
) (Result, error) {
result := Result{
Expand All @@ -34,6 +36,7 @@ func NewResult(
Status: status,
StatusCode: statusCode,
Headers: headers,
Protocol: protocol,
}

if len(bodyRaw) > 0 {
Expand All @@ -56,12 +59,14 @@ func NewResult(
func (r *Result) Print(showHeaders bool) {
fmt.Println(r.Path)

// TODO: add protocol
// HTTP 1.1 200 OK
if r.StatusCode < 300 {
fmt.Println(printer.Green(r.Status))
fmt.Println(r.Protocol, printer.Green(r.Status))
} else if r.StatusCode >= 300 && r.StatusCode < 400 {
fmt.Println(printer.Cyan(r.Status))
fmt.Println(r.Protocol, printer.Cyan(r.Status))
} else {
fmt.Println(printer.Red(r.Status))
fmt.Println(r.Protocol, printer.Red(r.Status))
}

fmt.Println(fmt.Sprintf("%s: %s", printer.Cyan("Elapsed Time"), r.ElapsedTime))
Expand Down

0 comments on commit a1a949f

Please sign in to comment.