Skip to content

Instantly share code, notes, and snippets.

Created October 4, 2013 00:17
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
A simple HTTP server which serves static files in the working directory. By default serves on port 8080 or takes a port argument. Created as a fast replacement to Python's (python -m SimpleHTTPServer). Example usage: gosimplehttp 8000
package main
import (
func main() {
// Get the port
port := flag.Arg(0)
if len(port) == 0 {
port = "8080"
port = ":" + port
// Get the working directory
wd, err := os.Getwd()
if err != nil {
// Start the server
fmt.Printf("Server listening on http://localhost%s\nWatching directory %s\n", port, wd)
panic(http.ListenAndServe(port, http.FileServer(http.Dir(wd))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment