Don't blindly SetString.

This commit is contained in:
Alec Thomas
2018-09-22 21:18:22 +10:00
parent 0f67a38060
commit d648254c7d
+9
View File
@@ -368,6 +368,9 @@ func pathMapper(r *Registry) MapperFunc {
if target.Kind() == reflect.Slice {
return sliceDecoder(r)(ctx, target)
}
if target.Kind() != reflect.String {
return fmt.Errorf("\"path\" type must be applied to a string not %s", target.Type())
}
path := ctx.Scan.PopValue("file")
path = expandPath(path)
target.SetString(path)
@@ -380,6 +383,9 @@ func existingFileMapper(r *Registry) MapperFunc {
if target.Kind() == reflect.Slice {
return sliceDecoder(r)(ctx, target)
}
if target.Kind() != reflect.String {
return fmt.Errorf("\"existingfile\" type must be applied to a string not %s", target.Type())
}
path := ctx.Scan.PopValue("file")
path = expandPath(path)
stat, err := os.Stat(path)
@@ -399,6 +405,9 @@ func existingDirMapper(r *Registry) MapperFunc {
if target.Kind() == reflect.Slice {
return sliceDecoder(r)(ctx, target)
}
if target.Kind() != reflect.String {
return fmt.Errorf("\"existingdir\" must be applied to a string not %s", target.Type())
}
path := ctx.Scan.PopValue("file")
path = expandPath(path)
stat, err := os.Stat(path)