Unknown model· unknown
from ShareGPT 90K (shared ChatGPT conversations)
scrivi un webserver in go
- User
scrivi un webserver in go
- Assistant
Per scrivere un webserver in Go, è necessario utilizzare la libreria
net/httpinclusa in Go. Ecco un esempio di webserver che può servire come base per iniziare:codepackage main import ( "fmt" "net/http" ) func handler(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, "Hello, World!") } func main() { http.HandleFunc("/", handler) http.ListenAndServe(":8080", nil) }Questo webserver risponderà a qualsiasi richiesta HTTP all'indirizzo
http://localhost:8080con la stringa "Hello, World!".