Skip to content

Commit 6c4b4ea

Browse files
kveselkovjohnweldon
authored andcommitted
fixed warnings ifElseChain (#187)
* fixed warnings ifElseChain * fmt fix
1 parent 7deeac9 commit 6c4b4ea

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
lines changed

compare.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,13 @@ func (l *Conn) Compare(dn, attribute, value string) (bool, error) {
6969

7070
if packet.Children[1].Tag == ApplicationCompareResponse {
7171
resultCode, resultDescription := getLDAPResultCode(packet)
72-
if resultCode == LDAPResultCompareTrue {
72+
73+
switch {
74+
case resultCode == LDAPResultCompareTrue:
7375
return true, nil
74-
} else if resultCode == LDAPResultCompareFalse {
76+
case resultCode == LDAPResultCompareFalse:
7577
return false, nil
76-
} else {
78+
default:
7779
return false, NewError(resultCode, errors.New(resultDescription))
7880
}
7981
}

dn.go

+7-6
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ func ParseDN(str string) (*DN, error) {
9090

9191
for i := 0; i < len(str); i++ {
9292
char := str[i]
93-
if escaping {
93+
switch {
94+
case escaping:
9495
unescapedTrailingSpaces = 0
9596
escaping = false
9697
switch char {
@@ -112,10 +113,10 @@ func ParseDN(str string) (*DN, error) {
112113
}
113114
buffer.WriteByte(dst[0])
114115
i++
115-
} else if char == '\\' {
116+
case char == '\\':
116117
unescapedTrailingSpaces = 0
117118
escaping = true
118-
} else if char == '=' {
119+
case char == '=':
119120
attribute.Type = stringFromBuffer()
120121
// Special case: If the first character in the value is # the
121122
// following data is BER encoded so we can just fast forward
@@ -140,7 +141,7 @@ func ParseDN(str string) (*DN, error) {
140141
buffer.WriteString(packet.Data.String())
141142
i += len(data) - 1
142143
}
143-
} else if char == ',' || char == '+' {
144+
case char == ',' || char == '+':
144145
// We're done with this RDN or value, push it
145146
if len(attribute.Type) == 0 {
146147
return nil, errors.New("incomplete type, value pair")
@@ -153,10 +154,10 @@ func ParseDN(str string) (*DN, error) {
153154
rdn = new(RelativeDN)
154155
rdn.Attributes = make([]*AttributeTypeAndValue, 0)
155156
}
156-
} else if char == ' ' && buffer.Len() == 0 {
157+
case char == ' ' && buffer.Len() == 0:
157158
// ignore unescaped leading spaces
158159
continue
159-
} else {
160+
default:
160161
if char == ' ' {
161162
// Track unescaped spaces in case they are trailing and we need to remove them
162163
unescapedTrailingSpaces++

filter_test.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -195,13 +195,14 @@ func TestFilter(t *testing.T) {
195195
// Test Compiler and Decompiler
196196
for _, i := range testFilters {
197197
filter, err := CompileFilter(i.filterStr)
198-
if err != nil {
198+
switch {
199+
case err != nil:
199200
if i.expectedErr == "" || !strings.Contains(err.Error(), i.expectedErr) {
200201
t.Errorf("Problem compiling '%s' - '%v' (expected error to contain '%v')", i.filterStr, err, i.expectedErr)
201202
}
202-
} else if filter.Tag != ber.Tag(i.expectedType) {
203+
case filter.Tag != ber.Tag(i.expectedType):
203204
t.Errorf("%q Expected %q got %q", i.filterStr, FilterMap[uint64(i.expectedType)], FilterMap[uint64(filter.Tag)])
204-
} else {
205+
default:
205206
o, err := DecompileFilter(filter)
206207
if err != nil {
207208
t.Errorf("Problem compiling %s - %s", i.filterStr, err.Error())

0 commit comments

Comments
 (0)