Skip to content

Commit

Permalink
Refactor: drop else statements where if block ends with a return (#865)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandear authored Oct 19, 2023
1 parent 247397c commit ecd1897
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 14 deletions.
3 changes: 1 addition & 2 deletions middleware/compress.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,9 +332,8 @@ func (cw *compressResponseWriter) Write(p []byte) (int, error) {
func (cw *compressResponseWriter) writer() io.Writer {
if cw.compressible {
return cw.w
} else {
return cw.ResponseWriter
}
return cw.ResponseWriter
}

type compressFlusher interface {
Expand Down
13 changes: 6 additions & 7 deletions middleware/recoverer.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,14 @@ func (s prettyStack) decorateLine(line string, useColor bool, num int) (string,
line = strings.TrimSpace(line)
if strings.HasPrefix(line, "\t") || strings.Contains(line, ".go:") {
return s.decorateSourceLine(line, useColor, num)
} else if strings.HasSuffix(line, ")") {
}
if strings.HasSuffix(line, ")") {
return s.decorateFuncCallLine(line, useColor, num)
} else {
if strings.HasPrefix(line, "\t") {
return strings.Replace(line, "\t", " ", 1), nil
} else {
return fmt.Sprintf(" %s\n", line), nil
}
}
if strings.HasPrefix(line, "\t") {
return strings.Replace(line, "\t", " ", 1), nil
}
return fmt.Sprintf(" %s\n", line), nil
}

func (s prettyStack) decorateFuncCallLine(line string, useColor bool, num int) (string, error) {
Expand Down
6 changes: 1 addition & 5 deletions middleware/route_headers.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,7 @@ func NewPattern(value string) Pattern {

func (p Pattern) Match(v string) bool {
if !p.wildcard {
if p.prefix == v {
return true
} else {
return false
}
return p.prefix == v
}
return len(v) >= len(p.prefix+p.suffix) && strings.HasPrefix(v, p.prefix) && strings.HasSuffix(v, p.suffix)
}

0 comments on commit ecd1897

Please sign in to comment.