A web blog and personal homepage engine written in Go.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

27 lines
503 B

  1. package responses
  2. import (
  3. "mime"
  4. "net/http"
  5. "path/filepath"
  6. "git.kirsle.net/apps/gophertype/pkg/bundled"
  7. )
  8. // SendFile sends a file from bindata or the user root.
  9. func SendFile(w http.ResponseWriter, r *http.Request, path string) {
  10. mimeType := mime.TypeByExtension(filepath.Ext(path))
  11. if mimeType == "" {
  12. mimeType = "text/plain"
  13. }
  14. w.Header().Set("Content-Type", mimeType)
  15. if b, err := bundled.Asset(path); err == nil {
  16. w.Write(b)
  17. return
  18. }
  19. http.ServeFile(w, r, "pvt-www/"+path)
  20. }