Skip to content

Commit

Permalink
solve potential nil error for str.When
Browse files Browse the repository at this point in the history
  • Loading branch information
kkumar-gcc committed Sep 12, 2024
1 parent 610ac59 commit 51de4fe
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions support/str/str.go
Original file line number Diff line number Diff line change
Expand Up @@ -804,12 +804,14 @@ func (s *String) Upper() *String {
}

// When returns the String instance with the given callback applied if the given condition is true.
// If the condition is false, the fallback callback is applied.(if provided)
// If the condition is false, the fallback callback is applied (if provided).
func (s *String) When(condition bool, callback ...func(*String) *String) *String {
if condition {
return callback[0](s)
if len(callback) > 0 && callback[0] != nil {
return callback[0](s)
}
} else {
if len(callback) > 1 {
if len(callback) > 1 && callback[1] != nil {
return callback[1](s)
}
}
Expand Down

0 comments on commit 51de4fe

Please sign in to comment.