Skip to content

Instantly share code, notes, and snippets.

@vharsh
Created May 3, 2018 08:40
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/bf215504af1521cecc676b1d31ebbd02 to your computer and use it in GitHub Desktop.
Save vharsh/bf215504af1521cecc676b1d31ebbd02 to your computer and use it in GitHub Desktop.
Expose your directory's files over HTTP
// 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]
http.ListenAndServe(":8080", http.FileServer(http.Dir(dir)))
} else {
println("Usage ./fileserver /path/to/directory")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment