Add function Validate that creates an error when a condition is not met (#221)

This commit is contained in:
Corentin Clabaut
2022-10-04 21:28:29 +02:00
committed by GitHub
parent c190e196a1
commit 8e8ccc1047
3 changed files with 37 additions and 0 deletions

View File

@@ -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 {