Skip to content

Instantly share code, notes, and snippets.

@cheikhsimsol
Created January 20, 2024 20:17
Show Gist options
  • Save cheikhsimsol/a0c7f165315a62f73af516e8dab063be to your computer and use it in GitHub Desktop.
Save cheikhsimsol/a0c7f165315a62f73af516e8dab063be to your computer and use it in GitHub Desktop.
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