-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: improve error messages of 422 errors (#133)
- Loading branch information
1 parent
acfb26f
commit be19e61
Showing
4 changed files
with
33 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,36 @@ | ||
package utils | ||
|
||
import "fmt" | ||
import ( | ||
"fmt" | ||
"unicode" | ||
) | ||
|
||
func LowercaseMessage(message string) string { | ||
if len(message) >= 2 { | ||
firstChar := rune(message[0]) | ||
secondChar := rune(message[1]) | ||
|
||
if !unicode.IsLower(firstChar) && unicode.IsLower(secondChar) { | ||
return string(unicode.ToLower(firstChar)) + message[1:] | ||
} | ||
} | ||
return message | ||
} | ||
|
||
func Pluralize(count int64, singular string) string { | ||
if count == 1 { | ||
return fmt.Sprintf("%d %s", count, singular) | ||
} | ||
return fmt.Sprintf("%d %ss", count, singular) | ||
} | ||
|
||
func RemoveTrailingPeriod(message string) string { | ||
if len(message) > 0 && message[len(message)-1] == '.' { | ||
return message[:len(message)-1] | ||
} | ||
return message | ||
} | ||
|
||
func TextFromSentence(message string) string { | ||
return RemoveTrailingPeriod(LowercaseMessage(message)) | ||
} |