Created
January 20, 2024 20:17
-
-
Save cheikhsimsol/a0c7f165315a62f73af516e8dab063be to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"net/http" | |
) | |
func main() { | |
mux := http.NewServeMux() | |
// Map a route to handle requests to the root path ("/") | |
mux.HandleFunc("GET 127.0.0.1/", func(w http.ResponseWriter, r *http.Request) { | |
fmt.Fprint(w, "Hello") | |
}) | |
mux.HandleFunc("GET localhost/", func(w http.ResponseWriter, r *http.Request) { | |
fmt.Fprint(w, "Bonjour") | |
}) | |
// Create a server using the default ServeMux | |
server := &http.Server{ | |
Addr: ":8080", // Set the server address and port | |
Handler: mux, // Use the custom ServeMux | |
} | |
// Start the server | |
fmt.Println("Server is listening on http://localhost:8080") | |
err := server.ListenAndServe() | |
if err != nil { | |
fmt.Println("Error:", err) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment