feat: Implement platform-specific hosts file path retrieval
- Created a new `platform` package to handle OS-specific hosts file paths. - Added implementations for macOS, Linux, and Windows to retrieve the hosts file path. - Introduced tests for the `GetHostsFilePath` function to ensure correct behavior across platforms. feat: Add DNS resolver for IP lookups - Implemented a `resolver` package for performing DNS lookups. - Created a `DNSResolver` struct with a `LookupIP` method to handle A-record lookups and CNAME resolution. - Added comprehensive tests for various DNS scenarios, including CNAME chains and error handling. chore: Refactor project structure and update dependencies - Restructured the project to follow Go's standard package layout. - Updated `go.mod` to Go 1.20 and added `golang.org/x/net` dependency. - Removed old source files and ensured a clean build with all tests passing.
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
package hostfile
|
||||
|
||||
import "os"
|
||||
|
||||
// FileSystem abstracts filesystem operations for testability.
|
||||
type FileSystem interface {
|
||||
ReadFile(path string) ([]byte, error)
|
||||
WriteFile(path string, data []byte, perm os.FileMode) error
|
||||
Stat(path string) (os.FileInfo, error)
|
||||
CreateTemp(dir, pattern string) (*os.File, error)
|
||||
Rename(oldpath, newpath string) error
|
||||
Remove(path string) error
|
||||
Chmod(path string, mode os.FileMode) error
|
||||
}
|
||||
|
||||
// OSFileSystem implements FileSystem using real OS calls.
|
||||
type OSFileSystem struct{}
|
||||
|
||||
func (OSFileSystem) ReadFile(path string) ([]byte, error) { return os.ReadFile(path) }
|
||||
func (OSFileSystem) WriteFile(path string, data []byte, perm os.FileMode) error {
|
||||
return os.WriteFile(path, data, perm)
|
||||
}
|
||||
func (OSFileSystem) Stat(path string) (os.FileInfo, error) { return os.Stat(path) }
|
||||
func (OSFileSystem) CreateTemp(dir, pattern string) (*os.File, error) {
|
||||
return os.CreateTemp(dir, pattern)
|
||||
}
|
||||
func (OSFileSystem) Rename(oldpath, newpath string) error { return os.Rename(oldpath, newpath) }
|
||||
func (OSFileSystem) Remove(path string) error { return os.Remove(path) }
|
||||
func (OSFileSystem) Chmod(path string, mode os.FileMode) error {
|
||||
return os.Chmod(path, mode)
|
||||
}
|
||||
Reference in New Issue
Block a user