gpt-4.1-mini-2025-04-14· OpenAI
LMArena Human Preference 140K
write me an http server in golang.
- User
write me an http server in golang.
- Assistant
Certainly! Here's a simple HTTP server written in Go. This server listens on port 8080 and responds with "Hello, World!" to any request.
package main import ( "fmt" "net/http" ) func handler(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, "Hello, World!") } func main() { http.HandleFunc("/", handler) fmt.Println("Starting server at :8080") if err := http.ListenAndServe(":8080", nil); err != nil { fmt.Println("Server failed:", err) } }How to run:
- Save the code to a file, e.g.,
server.go. - Run
go run server.go. - Open your browser and go to
http://localhost:8080.
You should see the message:
Hello, World!If you want me to add more features (like routing, JSON responses, or middleware), just let me know!
- Save the code to a file, e.g.,
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.