switch
with single case can be rewritten as if
or if-else
CRT-A0014214func (c *Context) ServeContent(name string, r io.ReadSeeker, params ...any) {
215 modtime := time.Now()
216 for _, p := range params {
217 switch v := p.(type) {218 case time.Time:
219 modtime = v
220 }
switch
statements with a single case
can be rewritten as if-else
or if
.
Single case
switch
can be replaced by if-else
as it appears to be more
readable. This does not apply to type switch
.
switch ok {
case true:
// body
}
if ok {
// body
}