package main import ( "flag" "fmt" "net/http" "os" ) func main() { var port string var dir string flag.StringVar(&port, "port", "8000", "the port of the HTTP file server") flag.StringVar(&dir, "dir", "", "the directory to serve files from (defaults to the current working directory)") flag.Parse() // If no directory is provided, use the current working directory if dir == "" { cwd, err := os.Getwd() if err != nil { fmt.Println("Error getting current working directory:", err) return } dir = cwd } fmt.Printf("Serving HTTP on 0.0.0.0 port %s from directory %s\n", port, dir) h := http.FileServer(http.Dir(dir)) err := http.ListenAndServe(":"+port, h) if err != nil { fmt.Println("Error starting server:", err) } }