cloudflare/cloudflared
Publicmirrored from https://github.com/cloudflare/cloudflaredAvailable
cmd/cloudflared/tunnel/filesystem.go
26lines · modecode
| 1 | package tunnel |
| 2 | |
| 3 | import ( |
| 4 | "os" |
| 5 | ) |
| 6 | |
| 7 | // Abstract away details of reading files, so that SubcommandContext can read |
| 8 | // from either the real filesystem, or a mock (when running unit tests). |
| 9 | type fileSystem interface { |
| 10 | readFile(filePath string) ([]byte, error) |
| 11 | validFilePath(path string) bool |
| 12 | } |
| 13 | |
| 14 | type realFileSystem struct{} |
| 15 | |
| 16 | func (fs realFileSystem) validFilePath(path string) bool { |
| 17 | fileStat, err := os.Stat(path) |
| 18 | if err != nil { |
| 19 | return false |
| 20 | } |
| 21 | return !fileStat.IsDir() |
| 22 | } |
| 23 | |
| 24 | func (fs realFileSystem) readFile(filePath string) ([]byte, error) { |
| 25 | return os.ReadFile(filePath) |
| 26 | } |
| 27 | |