Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various changes regarding code readibility #523

Merged
merged 5 commits into from
Feb 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions args.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func (a *Args) AppendBytes(dst []byte) []byte {
for i, n := 0, len(a.args); i < n; i++ {
kv := &a.args[i]
dst = AppendQuotedArg(dst, kv.key)
if kv.noValue == argsHasValue {
if !kv.noValue {
dst = append(dst, '=')
if len(kv.value) > 0 {
dst = AppendQuotedArg(dst, kv.value)
Expand Down Expand Up @@ -370,7 +370,7 @@ func copyArgs(dst, src []argsKV) []argsKV {
dstKV := &dst[i]
srcKV := &src[i]
dstKV.key = append(dstKV.key[:0], srcKV.key...)
if srcKV.noValue == argsNoValue {
if srcKV.noValue {
dstKV.value = dstKV.value[:0]
} else {
dstKV.value = append(dstKV.value[:0], srcKV.value...)
Expand Down Expand Up @@ -407,7 +407,7 @@ func setArg(h []argsKV, key, value string, noValue bool) []argsKV {
for i := 0; i < n; i++ {
kv := &h[i]
if key == string(kv.key) {
if noValue == argsNoValue {
if noValue {
kv.value = kv.value[:0]
} else {
kv.value = append(kv.value[:0], value...)
Expand All @@ -427,7 +427,7 @@ func appendArg(args []argsKV, key, value string, noValue bool) []argsKV {
var kv *argsKV
args, kv = allocArg(args)
kv.key = append(kv.key[:0], key...)
if noValue == argsNoValue {
if noValue {
kv.value = kv.value[:0]
} else {
kv.value = append(kv.value[:0], value...)
Expand Down
8 changes: 2 additions & 6 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,7 @@ func TestClientRedirectSameSchema(t *testing.T) {
return
}

var reqClient *HostClient

reqClient = &HostClient{
reqClient := &HostClient{
IsTLS: true,
Addr: urlParsed.Host,
TLSConfig: &tls.Config{
Expand Down Expand Up @@ -117,9 +115,7 @@ func TestClientRedirectChangingSchemaHttp2Https(t *testing.T) {
return
}

var reqClient *HostClient

reqClient = &HostClient{
reqClient := &HostClient{
Addr: urlParsed.Host,
TLSConfig: &tls.Config{
InsecureSkipVerify: true,
Expand Down
2 changes: 1 addition & 1 deletion fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -958,7 +958,7 @@ func (h *fsHandler) createDirIndex(base *URI, dirPath string, mustCompress bool)
base.CopyTo(&u)
u.Update(string(u.Path()) + "/")

sort.Sort(sort.StringSlice(filenames))
sort.Strings(filenames)
for _, name := range filenames {
u.Update(name)
pathEscaped := html.EscapeString(string(u.Path()))
Expand Down
6 changes: 3 additions & 3 deletions fs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func TestServeFileSmallNoReadFrom(t *testing.T) {
t.Fatalf("expected %d bytes, got %d bytes", len(teststr), n)
}

body := string(buf.Bytes())
body := buf.String()
if body != teststr {
t.Fatalf("expected '%s'", teststr)
}
Expand Down Expand Up @@ -534,7 +534,7 @@ func TestFSHandlerSingleThread(t *testing.T) {
if err != nil {
t.Fatalf("cannot read dirnames in cwd: %s", err)
}
sort.Sort(sort.StringSlice(filenames))
sort.Strings(filenames)

for i := 0; i < 3; i++ {
fsHandlerTest(t, requestHandler, filenames)
Expand All @@ -554,7 +554,7 @@ func TestFSHandlerConcurrent(t *testing.T) {
if err != nil {
t.Fatalf("cannot read dirnames in cwd: %s", err)
}
sort.Sort(sort.StringSlice(filenames))
sort.Strings(filenames)

concurrency := 10
ch := make(chan struct{}, concurrency)
Expand Down
4 changes: 2 additions & 2 deletions http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ func TestRequestUpdateURI(t *testing.T) {
if !strings.HasPrefix(s, "GET /123/432.html?aaa=bcse") {
t.Fatalf("cannot find %q in %q", "GET /123/432.html?aaa=bcse", s)
}
if strings.Index(s, "\r\nHost: foobar.com\r\n") < 0 {
if !strings.Contains(s, "\r\nHost: foobar.com\r\n") {
t.Fatalf("cannot find %q in %q", "\r\nHost: foobar.com\r\n", s)
}
}
Expand Down Expand Up @@ -1833,7 +1833,7 @@ Content-Type: application/json
t.Fatalf("unexpected error: %s", err)
}

if string(w.Bytes()) != s {
if w.String() != s {
t.Fatalf("unexpected output %q", w.Bytes())
}
}
3 changes: 1 addition & 2 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -1986,8 +1986,7 @@ func (s *Server) serveConn(c net.Conn) error {
}

if hijackHandler != nil {
var hjr io.Reader
hjr = c
var hjr io.Reader = c
if br != nil {
hjr = br
br = nil
Expand Down