fix golangci-lint
This commit is contained in:
parent
3f71a458e9
commit
ee7249e291
16
charts.go
16
charts.go
|
@ -31,7 +31,7 @@ $(function () { setInterval({{ .ViewID }}_sync, {{ .Interval }}); });
|
||||||
function {{ .ViewID }}_sync() {
|
function {{ .ViewID }}_sync() {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: "GET",
|
type: "GET",
|
||||||
url: "http://{{ .Addr }}{{ .ApiPath }}/{{ .Route }}",
|
url: "http://{{ .Addr }}{{ .APIPath }}/{{ .Route }}",
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
success: function (result) {
|
success: function (result) {
|
||||||
let opt = goecharts_{{ .ViewID }}.getOption();
|
let opt = goecharts_{{ .ViewID }}.getOption();
|
||||||
|
@ -71,13 +71,13 @@ func (c *Charts) genViewTemplate(vid, route string) string {
|
||||||
var d = struct {
|
var d = struct {
|
||||||
Interval int
|
Interval int
|
||||||
Addr string
|
Addr string
|
||||||
ApiPath string
|
APIPath string
|
||||||
Route string
|
Route string
|
||||||
ViewID string
|
ViewID string
|
||||||
}{
|
}{
|
||||||
Interval: int(refreshInterval.Milliseconds()),
|
Interval: int(refreshInterval.Milliseconds()),
|
||||||
Addr: c.linkAddr,
|
Addr: c.linkAddr,
|
||||||
ApiPath: apiPath,
|
APIPath: apiPath,
|
||||||
Route: route,
|
Route: route,
|
||||||
ViewID: vid,
|
ViewID: vid,
|
||||||
}
|
}
|
||||||
|
@ -166,12 +166,12 @@ func (c *Charts) Handler(ctx *fasthttp.RequestCtx) {
|
||||||
path := string(ctx.Path())
|
path := string(ctx.Path())
|
||||||
switch path {
|
switch path {
|
||||||
case assertsPath + "echarts.min.js":
|
case assertsPath + "echarts.min.js":
|
||||||
ctx.WriteString(EchartJS)
|
_, _ = ctx.WriteString(EchartJS)
|
||||||
case assertsPath + "jquery.min.js":
|
case assertsPath + "jquery.min.js":
|
||||||
ctx.WriteString(JqueryJS)
|
_, _ = ctx.WriteString(JqueryJS)
|
||||||
case "/":
|
case "/":
|
||||||
ctx.SetContentType("text/html")
|
ctx.SetContentType("text/html")
|
||||||
c.page.Render(ctx)
|
_ = c.page.Render(ctx)
|
||||||
default:
|
default:
|
||||||
if strings.HasPrefix(path, apiPath) {
|
if strings.HasPrefix(path, apiPath) {
|
||||||
view := path[len(apiPath)+1:]
|
view := path[len(apiPath)+1:]
|
||||||
|
@ -197,7 +197,7 @@ func (c *Charts) Handler(ctx *fasthttp.RequestCtx) {
|
||||||
Time: time.Now().Format(timeFormat),
|
Time: time.Now().Format(timeFormat),
|
||||||
Values: values,
|
Values: values,
|
||||||
}
|
}
|
||||||
json.NewEncoder(ctx).Encode(metrics)
|
_ = json.NewEncoder(ctx).Encode(metrics)
|
||||||
} else {
|
} else {
|
||||||
ctx.Error("NotFound", fasthttp.StatusNotFound)
|
ctx.Error("NotFound", fasthttp.StatusNotFound)
|
||||||
}
|
}
|
||||||
|
@ -208,5 +208,5 @@ func (c *Charts) Serve() {
|
||||||
server := fasthttp.Server{
|
server := fasthttp.Server{
|
||||||
Handler: cors.DefaultHandler().CorsMiddleware(c.Handler),
|
Handler: cors.DefaultHandler().CorsMiddleware(c.Handler),
|
||||||
}
|
}
|
||||||
server.Serve(c.ln)
|
_ = server.Serve(c.ln)
|
||||||
}
|
}
|
||||||
|
|
35
print.go
35
print.go
|
@ -21,7 +21,7 @@ var (
|
||||||
barEnd = "|"
|
barEnd = "|"
|
||||||
barSpinner = []string{"|", "/", "-", "\\"}
|
barSpinner = []string{"|", "/", "-", "\\"}
|
||||||
clearLine = []byte("\r\033[K")
|
clearLine = []byte("\r\033[K")
|
||||||
isTerminal = isatty.IsTerminal(os.Stdout.Fd()) || isatty.IsTerminal(os.Stdout.Fd())
|
isTerminal = isatty.IsTerminal(os.Stdout.Fd()) || isatty.IsCygwinTerminal(os.Stdout.Fd())
|
||||||
)
|
)
|
||||||
|
|
||||||
type Printer struct {
|
type Printer struct {
|
||||||
|
@ -39,7 +39,7 @@ func NewPrinter(maxNum int64, maxDuration time.Duration) *Printer {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Printer) updateProgressValue(rs *SnapshotReport) {
|
func (p *Printer) updateProgressValue(rs *SnapshotReport) {
|
||||||
p.pbInc += 1
|
p.pbInc++
|
||||||
if p.maxDuration > 0 {
|
if p.maxDuration > 0 {
|
||||||
n := rs.Elapsed
|
n := rs.Elapsed
|
||||||
if n > p.maxDuration {
|
if n > p.maxDuration {
|
||||||
|
@ -108,6 +108,7 @@ func (p *Printer) PrintLoop(snapshot func() *SnapshotReport, interval time.Durat
|
||||||
echo(true)
|
echo(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//nolint
|
||||||
const (
|
const (
|
||||||
FgBlackColor int = iota + 30
|
FgBlackColor int = iota + 30
|
||||||
FgRedColor
|
FgRedColor
|
||||||
|
@ -147,7 +148,7 @@ func alignBulk(bulk [][]string, aligns ...int) {
|
||||||
for _, b := range bulk {
|
for _, b := range bulk {
|
||||||
for i, ali := range aligns {
|
for i, ali := range aligns {
|
||||||
if len(b) >= i+1 {
|
if len(b) >= i+1 {
|
||||||
if i == len(aligns)-1 && ali == ALIGN_LEFT {
|
if i == len(aligns)-1 && ali == AlignLeft {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
b[i] = padString(b[i], " ", maxLen[i], ali)
|
b[i] = padString(b[i], " ", maxLen[i], ali)
|
||||||
|
@ -228,9 +229,9 @@ func (p *Printer) buildHistogram(snapshot *SnapshotReport, useSeconds bool, isFi
|
||||||
hisBulk = append(hisBulk, row)
|
hisBulk = append(hisBulk, row)
|
||||||
}
|
}
|
||||||
if isFinal {
|
if isFinal {
|
||||||
alignBulk(hisBulk, ALIGN_LEFT, ALIGN_RIGHT, ALIGN_RIGHT)
|
alignBulk(hisBulk, AlignLeft, AlignRight, AlignRight)
|
||||||
} else {
|
} else {
|
||||||
alignBulk(hisBulk, ALIGN_LEFT, ALIGN_RIGHT, ALIGN_LEFT)
|
alignBulk(hisBulk, AlignLeft, AlignRight, AlignLeft)
|
||||||
}
|
}
|
||||||
return hisBulk
|
return hisBulk
|
||||||
}
|
}
|
||||||
|
@ -242,9 +243,9 @@ func (p *Printer) buildPercentile(snapshot *SnapshotReport, useSeconds bool) [][
|
||||||
perc := formatFloat64(percentile.Percentile * 100)
|
perc := formatFloat64(percentile.Percentile * 100)
|
||||||
percBulk[0] = append(percBulk[0], "P"+perc)
|
percBulk[0] = append(percBulk[0], "P"+perc)
|
||||||
percBulk[1] = append(percBulk[1], durationToString(percentile.Latency, useSeconds))
|
percBulk[1] = append(percBulk[1], durationToString(percentile.Latency, useSeconds))
|
||||||
percAligns = append(percAligns, ALIGN_CENTER)
|
percAligns = append(percAligns, AlignCenter)
|
||||||
}
|
}
|
||||||
percAligns[0] = ALIGN_LEFT
|
percAligns[0] = AlignLeft
|
||||||
alignBulk(percBulk, percAligns...)
|
alignBulk(percBulk, percAligns...)
|
||||||
return percBulk
|
return percBulk
|
||||||
}
|
}
|
||||||
|
@ -272,7 +273,7 @@ func (p *Printer) buildStats(snapshot *SnapshotReport, useSeconds bool) [][]stri
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
alignBulk(statsBulk, ALIGN_LEFT, ALIGN_CENTER, ALIGN_CENTER, ALIGN_CENTER, ALIGN_CENTER)
|
alignBulk(statsBulk, AlignLeft, AlignCenter, AlignCenter, AlignCenter, AlignCenter)
|
||||||
return statsBulk
|
return statsBulk
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -285,7 +286,7 @@ func (p *Printer) buildErrors(snapshot *SnapshotReport) [][]string {
|
||||||
if errorsBulks != nil {
|
if errorsBulks != nil {
|
||||||
sort.Slice(errorsBulks, func(i, j int) bool { return errorsBulks[i][1] < errorsBulks[j][1] })
|
sort.Slice(errorsBulks, func(i, j int) bool { return errorsBulks[i][1] < errorsBulks[j][1] })
|
||||||
}
|
}
|
||||||
alignBulk(errorsBulks, ALIGN_LEFT, ALIGN_LEFT)
|
alignBulk(errorsBulks, AlignLeft, AlignLeft)
|
||||||
return errorsBulks
|
return errorsBulks
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -320,7 +321,7 @@ func (p *Printer) buildSummary(snapshot *SnapshotReport, isFinal bool) [][]strin
|
||||||
[]string{"Reads", fmt.Sprintf("%.3fMB/s", snapshot.ReadThroughput)},
|
[]string{"Reads", fmt.Sprintf("%.3fMB/s", snapshot.ReadThroughput)},
|
||||||
[]string{"Writes", fmt.Sprintf("%.3fMB/s", snapshot.WriteThroughput)},
|
[]string{"Writes", fmt.Sprintf("%.3fMB/s", snapshot.WriteThroughput)},
|
||||||
)
|
)
|
||||||
alignBulk(summarybulk, ALIGN_LEFT, ALIGN_RIGHT)
|
alignBulk(summarybulk, AlignLeft, AlignRight)
|
||||||
return summarybulk
|
return summarybulk
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -331,20 +332,20 @@ func displayWidth(str string) int {
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ALIGN_LEFT = iota
|
AlignLeft = iota
|
||||||
ALIGN_RIGHT
|
AlignRight
|
||||||
ALIGN_CENTER
|
AlignCenter
|
||||||
)
|
)
|
||||||
|
|
||||||
func padString(s, pad string, width int, align int) string {
|
func padString(s, pad string, width int, align int) string {
|
||||||
gap := width - displayWidth(s)
|
gap := width - displayWidth(s)
|
||||||
if gap > 0 {
|
if gap > 0 {
|
||||||
if align == ALIGN_LEFT {
|
if align == AlignLeft {
|
||||||
return s + strings.Repeat(pad, gap)
|
return s + strings.Repeat(pad, gap)
|
||||||
} else if align == ALIGN_RIGHT {
|
} else if align == AlignRight {
|
||||||
return strings.Repeat(pad, gap) + s
|
return strings.Repeat(pad, gap) + s
|
||||||
} else if align == ALIGN_CENTER {
|
} else if align == AlignCenter {
|
||||||
gapLeft := int(math.Ceil(float64(gap / 2)))
|
gapLeft := gap / 2
|
||||||
gapRight := gap - gapLeft
|
gapRight := gap - gapLeft
|
||||||
return strings.Repeat(pad, gapLeft) + s + strings.Repeat(pad, gapRight)
|
return strings.Repeat(pad, gapLeft) + s + strings.Repeat(pad, gapRight)
|
||||||
}
|
}
|
||||||
|
|
12
report.go
12
report.go
|
@ -104,14 +104,6 @@ func (s *StreamReport) insert(v float64) {
|
||||||
s.latencyStats.Update(v)
|
s.latencyStats.Update(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *StreamReport) percentiles() ([]float64, []float64) {
|
|
||||||
result := make([]float64, len(quantiles))
|
|
||||||
for i, f := range quantiles {
|
|
||||||
result[i] = s.latencyQuantile.Query(f)
|
|
||||||
}
|
|
||||||
return quantiles, result
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *StreamReport) Collect(records <-chan *ReportRecord) {
|
func (s *StreamReport) Collect(records <-chan *ReportRecord) {
|
||||||
latencyWithinSecTemp := &Stats{}
|
latencyWithinSecTemp := &Stats{}
|
||||||
go func() {
|
go func() {
|
||||||
|
@ -153,10 +145,10 @@ func (s *StreamReport) Collect(records <-chan *ReportRecord) {
|
||||||
latencyWithinSecTemp.Update(float64(r.cost))
|
latencyWithinSecTemp.Update(float64(r.cost))
|
||||||
s.insert(float64(r.cost))
|
s.insert(float64(r.cost))
|
||||||
if r.code != "" {
|
if r.code != "" {
|
||||||
s.codes[r.code] += 1
|
s.codes[r.code] ++
|
||||||
}
|
}
|
||||||
if r.error != "" {
|
if r.error != "" {
|
||||||
s.errors[r.error] += 1
|
s.errors[r.error] ++
|
||||||
}
|
}
|
||||||
s.readBytes = r.readBytes
|
s.readBytes = r.readBytes
|
||||||
s.writeBytes = r.writeBytes
|
s.writeBytes = r.writeBytes
|
||||||
|
|
43
requester.go
43
requester.go
|
@ -97,8 +97,6 @@ type Requester struct {
|
||||||
|
|
||||||
recordChan chan *ReportRecord
|
recordChan chan *ReportRecord
|
||||||
closeOnce sync.Once
|
closeOnce sync.Once
|
||||||
report *StreamReport
|
|
||||||
errCount int64
|
|
||||||
wg sync.WaitGroup
|
wg sync.WaitGroup
|
||||||
|
|
||||||
readBytes int64
|
readBytes int64
|
||||||
|
@ -173,7 +171,7 @@ func buildRequestClient(opt *ClientOpt, r *int64, w *int64) (*fasthttp.HostClien
|
||||||
DisableHeaderNamesNormalizing: true,
|
DisableHeaderNamesNormalizing: true,
|
||||||
}
|
}
|
||||||
if opt.socks5Proxy != "" {
|
if opt.socks5Proxy != "" {
|
||||||
if strings.Index(opt.socks5Proxy, "://") == -1 {
|
if !strings.Contains(opt.socks5Proxy, "://") {
|
||||||
opt.socks5Proxy = "socks5://" + opt.socks5Proxy
|
opt.socks5Proxy = "socks5://" + opt.socks5Proxy
|
||||||
}
|
}
|
||||||
httpClient.Dial = fasthttpproxy.FasthttpSocksDialer(opt.socks5Proxy)
|
httpClient.Dial = fasthttpproxy.FasthttpSocksDialer(opt.socks5Proxy)
|
||||||
|
@ -233,26 +231,25 @@ func (r *Requester) DoRequest(req *fasthttp.Request, resp *fasthttp.Response, rr
|
||||||
rr.code = ""
|
rr.code = ""
|
||||||
rr.error = err.Error()
|
rr.error = err.Error()
|
||||||
return
|
return
|
||||||
} else {
|
}
|
||||||
switch resp.StatusCode() / 100 {
|
switch resp.StatusCode() / 100 {
|
||||||
case 1:
|
case 1:
|
||||||
code = "1xx"
|
code = "1xx"
|
||||||
case 2:
|
case 2:
|
||||||
code = "2xx"
|
code = "2xx"
|
||||||
case 3:
|
case 3:
|
||||||
code = "3xx"
|
code = "3xx"
|
||||||
case 4:
|
case 4:
|
||||||
code = "4xx"
|
code = "4xx"
|
||||||
case 5:
|
case 5:
|
||||||
code = "5xx"
|
code = "5xx"
|
||||||
}
|
}
|
||||||
err = resp.BodyWriteTo(ioutil.Discard)
|
err = resp.BodyWriteTo(ioutil.Discard)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
rr.cost = time.Since(startTime) - t1
|
rr.cost = time.Since(startTime) - t1
|
||||||
rr.code = ""
|
rr.code = ""
|
||||||
rr.error = err.Error()
|
rr.error = err.Error()
|
||||||
return
|
return
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
rr.cost = time.Since(startTime) - t1
|
rr.cost = time.Since(startTime) - t1
|
||||||
|
|
Loading…
Reference in New Issue