Skip to content

Commit 7b57fa6

Browse files
committed
feat(config): print more info about validation
1 parent 67099f1 commit 7b57fa6

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

util/config.go

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -394,23 +394,32 @@ func validate(value interface{}) error {
394394
continue
395395
}
396396

397-
var value string
397+
var strVal string
398398

399399
if fieldType.Type.Kind() == reflect.Int {
400-
value = strconv.FormatInt(fieldValue.Int(), 10)
400+
strVal = strconv.FormatInt(fieldValue.Int(), 10)
401401
} else if fieldType.Type.Kind() == reflect.Uint {
402-
value = strconv.FormatUint(fieldValue.Uint(), 10)
402+
strVal = strconv.FormatUint(fieldValue.Uint(), 10)
403403
} else {
404-
value = fieldValue.String()
404+
strVal = fieldValue.String()
405405
}
406406

407-
match, _ := regexp.MatchString(rule, value)
408-
if !match {
409-
return fmt.Errorf(
410-
"value of field '%v' is not valid! (Must match regex: '%v')",
411-
fieldType.Name, rule,
412-
)
407+
match, _ := regexp.MatchString(rule, strVal)
408+
409+
if match {
410+
continue
411+
}
412+
413+
fieldName := strings.ToLower(fieldType.Name)
414+
415+
if strings.Contains(fieldName, "password") || strings.Contains(fieldName, "secret") || strings.Contains(fieldName, "key") {
416+
strVal = "***"
413417
}
418+
419+
return fmt.Errorf(
420+
"value of field '%v' is not valid: %v (Must match regex: '%v')",
421+
fieldType.Name, strVal, rule,
422+
)
414423
}
415424

416425
return nil

0 commit comments

Comments
 (0)