Created
March 8, 2013 22:08
-
-
Save technoweenie/5120302 to your computer and use it in GitHub Desktop.
hacking on a dumb script to expose the cwd over http. yikes! Inspired by the heel gem: http://rubygems.org/gems/heel
This file contains hidden or 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
package main | |
import ( | |
"fmt" | |
"io/ioutil" | |
"log" | |
"net/http" | |
"os" | |
) | |
func main() { | |
pwd, _ := os.Getwd() | |
http.HandleFunc("/", indexHandler(pwd)) | |
log.Fatal(http.ListenAndServe(":8080", nil)) | |
} | |
func indexHandler(pwd string) http.HandlerFunc { | |
return func(w http.ResponseWriter, r *http.Request) { | |
files, _ := ioutil.ReadDir(pwd) | |
fmt.Fprintf(w, "%s\n\n", pwd) | |
for _, file := range files { | |
fmt.Fprintf(w, "%s (%d)\n", file.Name(), file.Size()) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment