Skip to content

Instantly share code, notes, and snippets.

@technoweenie
Created March 8, 2013 22:08
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 technoweenie/5120302 to your computer and use it in GitHub Desktop.
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
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