Skip to content

Instantly share code, notes, and snippets.

@tomnomnom
Created January 21, 2015 14:20
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 tomnomnom/fbbd0641e2db30616967 to your computer and use it in GitHub Desktop.
Save tomnomnom/fbbd0641e2db30616967 to your computer and use it in GitHub Desktop.
lolstore
package main
import (
"fmt"
"io"
"log"
"net/http"
"os"
)
const dataDir = "./data"
func storeHandler(w http.ResponseWriter, r *http.Request) {
path := dataDir + r.RequestURI
switch r.Method {
case "GET":
http.ServeFile(w, r, path)
case "POST":
f, _ := os.Create(path)
io.Copy(f, r.Body)
default:
w.WriteHeader(http.StatusMethodNotAllowed)
fmt.Fprintf(w, "I'm afraid I can't do that.\n")
}
}
func main() {
http.HandleFunc("/", storeHandler)
http.ListenAndServe(":8080", nil)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment