Skip to content

Instantly share code, notes, and snippets.

@darkhelmet
Created November 23, 2012 23:55
Show Gist options
  • Save darkhelmet/4137752 to your computer and use it in GitHub Desktop.
Save darkhelmet/4137752 to your computer and use it in GitHub Desktop.
#!/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