Skip to content

Commit 7f00c5c

Browse files
committed
osxkeychain: use a switch for handling errors
Makes the error-handling slightly cleaner. Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent 1ed95cb commit 7f00c5c

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

osxkeychain/osxkeychain_darwin.go

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,14 @@ func (h Osxkeychain) Get(serverURL string) (string, string, error) {
9393
errMsg := C.keychain_get(s, &usernameLen, &username, &secretLen, &secret)
9494
if errMsg != nil {
9595
defer C.free(unsafe.Pointer(errMsg))
96-
goMsg := C.GoString(errMsg)
97-
if goMsg == errCredentialsNotFound {
96+
switch goMsg := C.GoString(errMsg); goMsg {
97+
case errCredentialsNotFound:
9898
return "", "", credentials.NewErrCredentialsNotFound()
99-
}
100-
if goMsg == errInteractionNotAllowed {
99+
case errInteractionNotAllowed:
101100
return "", "", ErrInteractionNotAllowed
101+
default:
102+
return "", "", errors.New(goMsg)
102103
}
103-
104-
return "", "", errors.New(goMsg)
105104
}
106105

107106
user := C.GoStringN(username, C.int(usernameLen))
@@ -124,15 +123,14 @@ func (h Osxkeychain) List() (map[string]string, error) {
124123
defer C.freeListData(&acctsC, listLenC)
125124
if errMsg != nil {
126125
defer C.free(unsafe.Pointer(errMsg))
127-
goMsg := C.GoString(errMsg)
128-
if goMsg == errCredentialsNotFound {
126+
switch goMsg := C.GoString(errMsg); goMsg {
127+
case errCredentialsNotFound:
129128
return make(map[string]string), nil
130-
}
131-
if goMsg == errInteractionNotAllowed {
129+
case errInteractionNotAllowed:
132130
return nil, ErrInteractionNotAllowed
131+
default:
132+
return nil, errors.New(goMsg)
133133
}
134-
135-
return nil, errors.New(goMsg)
136134
}
137135

138136
var listLen int

0 commit comments

Comments
 (0)