Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Simple Static File Server in Go
Serve is a very simple static file server in go
-p="8100": port to serve on
-d=".": the directory of static files to host
Navigating to http://localhost:8100 will display the index.html or directory
listing file.
package main
import (
func main() {
port := flag.String("p", "8100", "port to serve on")
directory := flag.String("d", ".", "the directory of static file to host")
http.Handle("/", http.FileServer(http.Dir(*directory)))
log.Printf("Serving %s on HTTP port: %s\n", *directory, *port)
log.Fatal(http.ListenAndServe(":"+*port, nil))
Copy link

kfelter commented May 10, 2022


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment