package main import ( "fmt" "net/http" ) func main() { mux := http.NewServeMux() mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, "Hello, World!") }) mux.HandleFunc("/about", func(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, "This is the about page.") }) fmt.Println("Server listening on localhost:8080") http.ListenAndServe(":8080", mux) }
package main import ( "net/http" ) func main() { mux := http.NewServeMux() mux.Handle("/", http.FileServer(http.Dir("./static"))) http.ListenAndServe(":8080", mux) }In this example, we create a new ServeMux instance and register a FileServer handler using the Handle method. The FileServer handler serves static files from the "./static" directory in response to any request that matches the root URL path. We then start the HTTP server using the ListenAndServe method. Package library: net/http.