(val interface{})
| 44 | } |
| 45 | |
| 46 | func IsExistingFile(val interface{}) error { |
| 47 | if str, ok := val.(string); ok { |
| 48 | info, err := os.Stat(str) |
| 49 | if os.IsNotExist(err) { |
| 50 | return fmt.Errorf("\"%s\" is not a valid file path", str) |
| 51 | } |
| 52 | if info.IsDir() { |
| 53 | return fmt.Errorf("\"%s\" is a directory, the path must be a file", str) |
| 54 | } |
| 55 | } else { |
| 56 | return fmt.Errorf("cannot check value on response of type %v", reflect.TypeOf(val).Name()) |
| 57 | } |
| 58 | // path is real file |
| 59 | return nil |
| 60 | } |
no outgoing calls
no test coverage detected