Skip to content

Instantly share code, notes, and snippets.

@yllan
Created May 27, 2013 04:02
Show Gist options
  • Select an option

  • Save yllan/5655140 to your computer and use it in GitHub Desktop.

Select an option

Save yllan/5655140 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"net/http"
)
const lenDownload = len("/dl/")
func downloadHandler(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, "./files/" + r.URL.Path[lenDownload:])
}
func handler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Lemon")
}
func main() {
http.HandleFunc("/", handler)
http.HandleFunc("/dl/", downloadHandler)
http.ListenAndServe(":8181", nil)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment