Created
November 23, 2012 23:55
-
-
Save darkhelmet/4137752 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env bash | |
# Usage: dh serve path/to/serve | |
# Summary: Serve a directory on port 8080 | |
tmpfile="/tmp/serve.$$.go" | |
dir=`greadlink -f $1` | |
if [ ! -d "$dir" ]; then | |
exec dh help serve | |
fi | |
cat <<EOF >$tmpfile | |
package main | |
import ( | |
"net/http" | |
"log" | |
) | |
func main() { | |
log.Printf("Serving %s on :8080", "$dir") | |
err := http.ListenAndServe(":8080", http.FileServer(http.Dir("$dir"))) | |
if err != nil { | |
log.Fatalf("failed serving: %s", err) | |
} | |
} | |
EOF | |
go run $tmpfile |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment