Pull request:* all: fix all staticcheck SA warnings
Merge in DNS/adguard-home from 2238-fix-static-analisys-warnings to master Squashed commit of the following: commit 721ca6fa1cbfdfe9d414e6ed52fec4a64653fb52 Author: Eugene Burkov <e.burkov@adguard.com> Date: Fri Oct 30 15:48:10 2020 +0300 * all: fix all staticcheck SA warnings Closes #2238.
This commit is contained in:
@@ -64,6 +64,7 @@ package util
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"html/template"
|
||||
"io"
|
||||
@@ -94,14 +95,11 @@ func PProfRegisterWebHandlers(mux *http.ServeMux) {
|
||||
func Cmdline(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("X-Content-Type-Options", "nosniff")
|
||||
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
|
||||
fmt.Fprintf(w, strings.Join(os.Args, "\x00"))
|
||||
fmt.Fprint(w, strings.Join(os.Args, "\x00"))
|
||||
}
|
||||
|
||||
func sleep(w http.ResponseWriter, d time.Duration) {
|
||||
var clientGone <-chan bool
|
||||
if cn, ok := w.(http.CloseNotifier); ok {
|
||||
clientGone = cn.CloseNotify()
|
||||
}
|
||||
func sleep(ctx context.Context, d time.Duration) {
|
||||
clientGone := ctx.Done()
|
||||
select {
|
||||
case <-time.After(d):
|
||||
case <-clientGone:
|
||||
@@ -146,7 +144,7 @@ func Profile(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Sprintf("Could not enable CPU profiling: %s", err))
|
||||
return
|
||||
}
|
||||
sleep(w, time.Duration(sec)*time.Second)
|
||||
sleep(r.Context(), time.Duration(sec)*time.Second)
|
||||
pprof.StopCPUProfile()
|
||||
}
|
||||
|
||||
@@ -175,7 +173,7 @@ func Trace(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Sprintf("Could not enable tracing: %s", err))
|
||||
return
|
||||
}
|
||||
sleep(w, time.Duration(sec*float64(time.Second)))
|
||||
sleep(r.Context(), time.Duration(sec*float64(time.Second)))
|
||||
trace.Stop()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user