rushlink/fileupload.go
2021-05-07 10:17:17 +02:00

31 lines
584 B
Go

package rushlink
import (
"log"
"net/http"
"github.com/pkg/errors"
)
// FileUploadFileSystem is a HTTP filesystem handler
type FileUploadFileSystem struct {
fs http.FileSystem
}
// Open opens a file
func (fs FileUploadFileSystem) Open(path string) (http.File, error) {
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
}