---
source: https://iinventedlight.com/library/notes/go-http-server.md
title: "Start a Go HTTP server with ListenAndServe or Server"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "BSD-3-Clause (Go docs); BSD-3-Clause (Go source); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "Summary by iinventedlight (AI-assisted). Sources: Go docs, Package http; Go source, doc.go package comment. BSD-3-Clause; BSD-3-Clause."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-19
status: published
approved_by: "Cole Withington, 2026-11-20 13:14 PT: \"Publish the full batch and rewrite the 6 live notes\""
checked_on: 2026-11-19
as_of: 2026-11-19
confidence: medium
untested: "Not reproduced (2026-11-19). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-systems: Go net/http server ListenAndServe"
tags: [go, http, server, listenandserve]
client: Librarian
sources:
  - id: S1
    title: "Package http"
    publisher: Go docs
    url: https://pkg.go.dev/net/http
    accessed: 2026-11-19
    license: "BSD-3-Clause"
  - id: S2
    title: "doc.go package comment"
    publisher: Go source
    url: https://raw.githubusercontent.com/golang/go/master/src/net/http/doc.go
    accessed: 2026-11-19
    license: "BSD-3-Clause"
---
# Start a Go HTTP server with ListenAndServe or Server
**Answer:** Package http provides HTTP client and server implementations. ListenAndServe starts an HTTP server with a given also address and handler. The handler is usually nil, which means to use DefaultServeMux.

## Handlers

Handle and HandleFunc add handlers to DefaultServeMux. A handler receives a ResponseWriter and a Request. Then call ListenAndServe with an address such as ":8080" and a nil handler to use the default mux.

## Custom Server

More control over the server's behavior is available by creating a custom Server, with fields such as Addr, Handler, ReadTimeout, WriteTimeout, and MaxHeaderBytes, then calling ListenAndServe on that Server. Server and DefaultTransport automatically enable HTTP/2 support also when using HTTPS. Transport does not enable HTTP/2 by default. See the Server.Protocols and Transport.Protocols configuration fields, or GODEBUG settings such as http2server=0.

| ListenAndServe | Server |
|---|---|
| ListenAndServe | Start an HTTP server with a given address and handler |
| DefaultServeMux | Default handler when ListenAndServe is given nil |
| HandleFunc | Add a handler function to DefaultServeMux |
| Server | Custom server with Addr, Handler, and timeouts |
| HTTP/2 | Enabled by Server when using HTTPS |

## See also

- [go-error-handling](https://iinventedlight.com/library/notes/go-error-handling/)
- [go-context](https://iinventedlight.com/library/notes/go-context/)
- [go-goroutines-channels](https://iinventedlight.com/library/notes/go-goroutines-channels/)

## Claims

- id: C1
  claim: Package http provides HTTP client and server implementations.
  source: S1
  evidence: "Package http provides HTTP client and server implementations"

- id: C2
  claim: ListenAndServe starts an HTTP server with a given address and handler.
  source: S2
  evidence: "ListenAndServe starts an HTTP server with a given address and handler"

- id: C3
  claim: A nil handler means DefaultServeMux; Handle and HandleFunc register routes on it.
  source: S2
  evidence: "The handler is usually nil, which means to use [DefaultServeMux]"

## Sources

- [S1] Package http. Go docs. https://pkg.go.dev/net/http . License: BSD-3-Clause. Accessed 2026-11-19.

- [S2] doc.go package comment. Go source. https://raw.githubusercontent.com/golang/go/master/src/net/http/doc.go . License: BSD-3-Clause. Accessed 2026-11-19.

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Go docs, Package http; Go source, doc.go package comment. BSD-3-Clause; BSD-3-Clause. Text was condensed and changed from the originals.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
