Skip to content

Instantly share code, notes, and snippets.

@marcusandre
Last active December 16, 2015 16:55
Show Gist options
  • Save marcusandre/4eb7ac1402af782dc6a5 to your computer and use it in GitHub Desktop.
Save marcusandre/4eb7ac1402af782dc6a5 to your computer and use it in GitHub Desktop.
Serve static files using http.FileServer
mkdir files
echo "32c3 is coming!" > files/file.txt
nohup go run main.go > /dev/null &
curl localhost:8080/file.txt
package main
import (
"log"
"net/http"
)
func main() {
http.Handle("/", http.StripPrefix("/", http.FileServer(http.Dir("files"))))
if err := http.ListenAndServe(":8080", nil); err != nil {
log.Fatal("ListenAndServe: ", err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment