How to Build a Simple Web Server in Golang to Serve Static HTML Pages

Quick little demonstration of how to server static HTML pages using Golang. This example assumes both your index.html and webserver.go files are in the same directory:

// REFERENCE (Simple Static Web Server in Go):
package main
import (
func main() {
http.Handle("/", http.FileServer(http.Dir("./")))
http.ListenAndServe(":3000", nil)
view raw webserver.go hosted with ❤ by GitHub
<!DOCTYPE html>
<h1>My Super Sweet Homepage</h1>
<button onclick="doStuff()">CLICK HERE</button>
function doStuff() {
alert("do stuff!");
view raw index.html hosted with ❤ by GitHub

Need routes to other pages? Check out this example I have posted on GitHub: SimpleGolangWebServer

Need to serve up JSON instead of HTML? Check out this example by Tom Hudson: simple-json-api.go