Skip to content

Commit

Permalink
Merge pull request #26 from Fenny/master
Browse files Browse the repository at this point in the history
🛠 add default
  • Loading branch information
Fenny authored Nov 5, 2020
2 parents ba358df + f4c0d33 commit 30753dd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 8 additions & 0 deletions bytes.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,11 @@ func EqualsFold(b, s []byte) (equals bool) {
}
return
}

// DefaultBytes returns the provided fallback value if []byte is empty
func DefaultBytes(value []byte, defaultValue []byte) []byte {
if len(value) <= 0 {
return defaultValue
}
return value
}
4 changes: 2 additions & 2 deletions strings.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ func TrimRight(s string, cutset byte) string {
return s[:lenStr]
}

// Default returns the provided fallback value if string is empty
func Default(value string, defaultValue string) string {
// DefaultString returns the provided fallback value if string is empty
func DefaultString(value string, defaultValue string) string {
if len(value) <= 0 {
return defaultValue
}
Expand Down

0 comments on commit 30753dd

Please sign in to comment.