-
Notifications
You must be signed in to change notification settings - Fork 0
/
output.go
71 lines (56 loc) · 1.36 KB
/
output.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package main
import (
"bytes"
"fmt"
"net/http"
"sort"
humanize "github.com/dustin/go-humanize"
"github.com/sirupsen/logrus"
)
// PrintURLInfo Print URL Info
func PrintURLInfo(resp *httpResponse) {
if resp.statusCode == http.StatusOK {
Report.PrintOKf("%s : %d", resp.url, resp.statusCode)
PrintHTTPHeaders(resp)
}
}
// PrintStats Print Stats
func PrintStats() {
// TODO: Implement
}
// PrintHTTPHeaders Print HTTP Headers
func PrintHTTPHeaders(resp *httpResponse) {
var buffer bytes.Buffer
var keys []string
for k := range resp.headers {
keys = append(keys, k)
}
sort.Strings(keys)
for _, k := range keys {
buffer.WriteString(fmt.Sprintf("%v: %v\n", k, resp.headers[k]))
}
Report.PrintCode(buffer.String())
}
func printOutput(args *processURLsArgs, ret *httpResponse) int {
Report.PrintSubHeader(ret.url)
errorCount := 0
for _, e := range ret.errs {
if e != nil {
Report.PrintError(e)
Logger.Error(e)
errorCount++
}
}
if RootLogger.GetLevel() == logrus.DebugLevel {
PrintURLInfo(ret)
}
if args.getHeadOny {
Report.PrintMessagef("Header ContentLength (Octets): %d\n", ret.contentLength)
} else if errorCount == 0 {
bodyLen := uint64(len(ret.body))
Report.PrintMessagef("Body Length: %d (%s)", bodyLen, humanize.Bytes(bodyLen))
Report.PrintMessagef("Request Time: %v", ret.requestTime)
}
PrintStats()
return errorCount
}