Last active
September 13, 2017 21:18
-
-
Save lambrospetrou/7b582954357778a42cc6e98477d32910 to your computer and use it in GitHub Desktop.
A simple HTTP server to serve a directory instead of python SimpleHTTPServer
This file contains 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
// To get the code git clone it as shown below: | |
// git clone https://gist.github.com/lambrospetrou/7b582954357778a42cc6e98477d32910.git gohttp | |
// | |
// Run either by `go run gohttp.go` | |
// Or do a `go install` and run it from your path directly with `gohttp` | |
// Example: `gohttp -d someDir/` | |
package main | |
import ( | |
"flag" | |
"fmt" | |
"log" | |
"net/http" | |
"path" | |
) | |
func main() { | |
port := flag.String("p", "11111", "Port to use") | |
directory := flag.String("d", ".", "Directory to serve") | |
flag.Parse() | |
var servedDir string = *directory | |
if !path.IsAbs(*directory) { | |
servedDir = path.Join(path.Dir("."), servedDir) | |
} | |
fmt.Println("Starting gohttp at ", *port, "and serving ", servedDir) | |
log.Fatal(http.ListenAndServe(":"+*port, http.FileServer(http.Dir(servedDir)))) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment