switch
with single case can be rewritten as if
or if-else
CRT-A0014235 models = mc.All()
236 for _, mi := range models {
237 for _, fi := range mi.Fields.FieldsRel {
238 switch fi.FieldType {239 case RelManyToMany:
240 for _, ffi := range fi.RelThroughModelInfo.Fields.FieldsRel {
241 switch ffi.FieldType {
150 }
151 fi.RelModelInfo = mii
152
153 switch fi.FieldType {154 case RelManyToMany:
155 if fi.RelThrough != "" {
156 if i := strings.LastIndex(fi.RelThrough, "."); i != -1 && len(fi.RelThrough) > (i+1) {
828 }
829
830 if cnt == 0 {
831 switch typ {832 case 1:
833 maps = make(Params)
834 }
171 return false, "", err
172 }
173
174 switch outputWriter.(type) {175 case io.WriteCloser:
176 outputWriter.(io.WriteCloser).Close()
177 }
77 env.Range(func(key, value interface{}) bool {
78 switch key := key.(type) {
79 case string:
80 switch val := value.(type) { 81 case string:
82 envs[key] = val
83 }
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
}