Skip to content

Instantly share code, notes, and snippets.

@vharsh
Created October 15, 2019 06:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vharsh/06f70a5af2aac3c2f9f2cf98374966b4 to your computer and use it in GitHub Desktop.
Save vharsh/06f70a5af2aac3c2f9f2cf98374966b4 to your computer and use it in GitHub Desktop.
file
// Good for a no nonsense file sharing across a network.
// This is an implementation of the similar functionality you get by doing `python -m SimpleHTTPServer`
// To use this you must compile this with a go compiler and pass the desired path to directory(to be hosted) as CLI arguments.
package main
import (
"net/http"
"os"
)
func main() {
var dir string
if len(os.Args) > 1 {
dir = os.Args[1]
}
port := ":8000"
if len(os.Args) > 2 {
port = ":" + os.Args[2]
}
http.ListenAndServe(port, http.FileServer(http.Dir(dir)))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment