Created
October 4, 2013 00:17
-
-
Save druska/6819136 to your computer and use it in GitHub Desktop.
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"flag" | |
"fmt" | |
"net/http" | |
"os" | |
) | |
func main() { | |
// Get the port | |
flag.Parse() | |
port := flag.Arg(0) | |
if len(port) == 0 { | |
port = "8080" | |
} | |
port = ":" + port | |
// Get the working directory | |
wd, err := os.Getwd() | |
if err != nil { | |
panic(err) | |
} | |
// 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