Files
dnshelper/platform/platform_windows.go
dyoder f0ce5a4042 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.
2026-03-03 18:37:02 -05:00

27 lines
649 B
Go

//go:build windows
package platform
import (
"fmt"
"os"
)
// GetHostsFilePath returns the absolute path to the system hosts file on Windows.
// Returns an error if the file does not exist or cannot be accessed.
func GetHostsFilePath() (string, error) {
var path string
if val, ok := os.LookupEnv("SystemRoot"); ok {
path = val + "\\System32\\drivers\\etc\\hosts"
} else {
path = "C:\\Windows\\System32\\drivers\\etc\\hosts"
}
if _, err := os.Stat(path); err != nil {
if os.IsNotExist(err) {
return "", fmt.Errorf("file does not exist: %s", path)
}
return "", fmt.Errorf("accessing hosts file: %w", err)
}
return path, nil
}