mirror of
https://github.com/shokinn/hosts-go.git
synced 2025-08-23 08:33:02 +00:00
- Created activeContext.md and productContext.md to outline project goals and current focus. - Established progress.md to track project milestones and tasks. - Developed projectbrief.md detailing application overview, requirements, and directory structure. - Documented systemPatterns.md to describe architecture and design patterns used. - Compiled techContext.md to specify technologies and development setup. - Implemented comprehensive unit tests in models_test.go for HostEntry and HostsFile functionalities.
83 lines
2.3 KiB
Go
83 lines
2.3 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
|
|
"hosts-go/internal/core"
|
|
)
|
|
|
|
func main() {
|
|
fmt.Println("hosts-go - Foundation Implementation")
|
|
fmt.Println("===================================")
|
|
|
|
// Create a new hosts file
|
|
hostsFile := core.NewHostsFile()
|
|
|
|
// Add some example entries to demonstrate the foundation
|
|
entry1, err := core.NewHostEntry("127.0.0.1", "localhost")
|
|
if err != nil {
|
|
log.Fatalf("Failed to create entry: %v", err)
|
|
}
|
|
entry1.Comment = "Local loopback"
|
|
|
|
entry2, err := core.NewHostEntry("192.168.1.100", "dev.example.com")
|
|
if err != nil {
|
|
log.Fatalf("Failed to create entry: %v", err)
|
|
}
|
|
entry2.AddAlias("www.dev.example.com")
|
|
entry2.AddAlias("api.dev.example.com")
|
|
entry2.Comment = "Development server"
|
|
|
|
entry3, err := core.NewHostEntry("10.0.0.50", "staging.example.com")
|
|
if err != nil {
|
|
log.Fatalf("Failed to create entry: %v", err)
|
|
}
|
|
entry3.Active = false // Inactive entry
|
|
entry3.Comment = "Staging server (disabled)"
|
|
|
|
// Add entries to hosts file
|
|
hostsFile.AddEntry(entry1)
|
|
hostsFile.AddEntry(entry2)
|
|
hostsFile.AddEntry(entry3)
|
|
|
|
// Demonstrate the foundation functionality
|
|
fmt.Printf("Total entries: %d\n", len(hostsFile.Entries))
|
|
fmt.Printf("Active entries: %d\n", len(hostsFile.ActiveEntries()))
|
|
fmt.Println()
|
|
|
|
fmt.Println("All entries:")
|
|
for i, entry := range hostsFile.Entries {
|
|
fmt.Printf("%d. %s\n", i+1, entry.String())
|
|
}
|
|
fmt.Println()
|
|
|
|
fmt.Println("Active entries only:")
|
|
for i, entry := range hostsFile.ActiveEntries() {
|
|
fmt.Printf("%d. %s\n", i+1, entry.String())
|
|
}
|
|
fmt.Println()
|
|
|
|
// Demonstrate search functionality
|
|
fmt.Println("Search demonstrations:")
|
|
if found := hostsFile.FindEntry("localhost"); found != nil {
|
|
fmt.Printf("Found 'localhost': %s\n", found.String())
|
|
}
|
|
|
|
if found := hostsFile.FindEntry("www.dev.example.com"); found != nil {
|
|
fmt.Printf("Found 'www.dev.example.com' (alias): %s\n", found.String())
|
|
}
|
|
|
|
if found := hostsFile.FindEntry("notfound.com"); found == nil {
|
|
fmt.Println("'notfound.com' not found (as expected)")
|
|
}
|
|
|
|
fmt.Println()
|
|
fmt.Println("Foundation implementation complete!")
|
|
fmt.Println("✅ Core data models working")
|
|
fmt.Println("✅ Validation system working")
|
|
fmt.Println("✅ Host entry management working")
|
|
fmt.Println("✅ Search and filtering working")
|
|
fmt.Println()
|
|
fmt.Println("Next steps: Implement hosts file parser and TUI components")
|
|
}
|