rushlink/fileupload.go

31 lines
584 B
Go
Raw Permalink Normal View History

2019-11-10 19:03:57 +01:00
package rushlink
import (
"log"
"net/http"
"github.com/pkg/errors"
)
// FileUploadFileSystem is a HTTP filesystem handler
type FileUploadFileSystem struct {
2019-11-10 19:03:57 +01:00
fs http.FileSystem
}
// Open opens a file
func (fs FileUploadFileSystem) Open(path string) (http.File, error) {
2019-11-10 19:03:57 +01:00
log.Println(path)
file, err := fs.fs.Open(path)
if err != nil {
return nil, errors.Wrap(err, "opening file")
}
stat, err := file.Stat()
if err != nil {
return nil, errors.Wrap(err, "file.Stat()")
}
if stat.IsDir() {
return nil, errors.New("directory index not allowed")
}
return file, nil
}