package main import ( "log" "net/http" ) func helloHandler(w http.ResponseWriter, r *http.Request) { if r.Method != http.MethodGet { http.Error(w, "Method not allowed", http.StatusMethodNotAllowed) return } w.Header().Set("Content-Type", "text/plain") w.WriteHeader(http.StatusOK) w.Write([]byte("Hello world")) } func main() { http.HandleFunc("/", helloHandler) port := ":8080" log.Printf("Server starting on port %s", port) log.Fatal(http.ListenAndServe(port, nil)) }