I'm writing a simple server as a project to help me learn Go. Here's its minimal form:
package main
import (
"io"
"net/http"
)
func serve(w http.ResponseWriter, r *http.Request) {
text := "HTTP/1.1 200 OK
" +
"Content-Type: text/html
" +
"Host: localhost:1234
" +
"Connection: close
" +
"
" +
"<!doctype html>
" +
"<html>...</html>
"
// Greet the user, ignoring their request.
io.WriteString(w, text)
}
func main() {
http.HandleFunc("/", serve)
http.ListenAndServe(":1234", nil)
}
It works as expected in terms that it sends the desired text when a client connects to localhost:1234
. But for some reason my browser displays the output as text instead of HTML, as desired. What am I doing wrong?