mirror of
https://github.com/samber/lo.git
synced 2025-09-27 04:15:58 +08:00
Add function Validate that creates an error when a condition is not met (#221)
This commit is contained in:
@@ -6,6 +6,14 @@ import (
|
||||
"reflect"
|
||||
)
|
||||
|
||||
// Validate is a helper that creates an error when a condition is not met.
|
||||
func Validate(ok bool, format string, args ...any) error {
|
||||
if !ok {
|
||||
return errors.New(fmt.Sprint(format, args))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func messageFromMsgAndArgs(msgAndArgs ...interface{}) string {
|
||||
if len(msgAndArgs) == 1 {
|
||||
if msgAsStr, ok := msgAndArgs[0].(string); ok {
|
||||
|
Reference in New Issue
Block a user