1
0
mirror of https://github.com/redis/go-redis.git synced 2025-08-06 01:35:48 +03:00

refactor(auth): early returns in cred listener

This commit is contained in:
Nedyalko Dyakov
2025-04-24 17:15:17 +03:00
parent 5f91e668ab
commit d0bfdabf6b

View File

@@ -14,22 +14,24 @@ type ReAuthCredentialsListener struct {
// It calls the reAuth function with the new credentials. // It calls the reAuth function with the new credentials.
// If the reAuth function returns an error, it calls the onErr function with the error. // If the reAuth function returns an error, it calls the onErr function with the error.
func (c *ReAuthCredentialsListener) OnNext(credentials Credentials) { func (c *ReAuthCredentialsListener) OnNext(credentials Credentials) {
if c.reAuth != nil { if c.reAuth == nil {
err := c.reAuth(credentials) return
if err != nil { }
if c.onErr != nil {
c.onErr(err) err := c.reAuth(credentials)
} if err != nil {
} c.OnError(err)
} }
} }
// OnError is called when an error occurs. // OnError is called when an error occurs.
// It can be called from both the credentials provider and the reAuth function. // It can be called from both the credentials provider and the reAuth function.
func (c *ReAuthCredentialsListener) OnError(err error) { func (c *ReAuthCredentialsListener) OnError(err error) {
if c.onErr != nil { if c.onErr == nil {
c.onErr(err) return
} }
c.onErr(err)
} }
// NewReAuthCredentialsListener creates a new ReAuthCredentialsListener. // NewReAuthCredentialsListener creates a new ReAuthCredentialsListener.