27 lines
503 B
Go
27 lines
503 B
Go
|
package responses
|
||
|
|
||
|
import (
|
||
|
"mime"
|
||
|
"net/http"
|
||
|
"path/filepath"
|
||
|
|
||
|
"git.kirsle.net/apps/gophertype/pkg/bundled"
|
||
|
)
|
||
|
|
||
|
// SendFile sends a file from bindata or the user root.
|
||
|
func SendFile(w http.ResponseWriter, r *http.Request, path string) {
|
||
|
mimeType := mime.TypeByExtension(filepath.Ext(path))
|
||
|
if mimeType == "" {
|
||
|
mimeType = "text/plain"
|
||
|
}
|
||
|
|
||
|
w.Header().Set("Content-Type", mimeType)
|
||
|
|
||
|
if b, err := bundled.Asset(path); err == nil {
|
||
|
w.Write(b)
|
||
|
return
|
||
|
}
|
||
|
|
||
|
http.ServeFile(w, r, "pvt-www/"+path)
|
||
|
}
|