разработка
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"git.company.lan/gopkg/filestore/remote"
|
||||
)
|
||||
|
||||
// Убеждаемся в том, что мы всегда реализуем интерфейс http.FileSystem.
|
||||
var _ http.FileSystem = (*HttpFS)(nil)
|
||||
|
||||
type HttpFS struct {
|
||||
@@ -18,14 +19,14 @@ type HttpFSOption func(*HttpFS)
|
||||
|
||||
// WithRemoteStorage
|
||||
func WithRemoteStorage(storage remote.Storage) HttpFSOption {
|
||||
return func(httpFS *HttpFS) {
|
||||
httpFS.remoteStorage = storage
|
||||
return func(f *HttpFS) {
|
||||
f.remoteStorage = storage
|
||||
}
|
||||
}
|
||||
|
||||
// NewHttpFS
|
||||
func NewHttpFS(dir string, opts ...HttpFSOption) (*HttpFS, error) {
|
||||
localStorage, err := NewLocalStorage(dir)
|
||||
// NewHttpFS создаёт новый экземпляр файловой системы.
|
||||
func NewHttpFS(rootDir string, opts ...HttpFSOption) (*HttpFS, error) {
|
||||
localStorage, err := NewLocalStorage(rootDir)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -42,7 +43,7 @@ func NewHttpFS(dir string, opts ...HttpFSOption) (*HttpFS, error) {
|
||||
return f, nil
|
||||
}
|
||||
|
||||
// Open
|
||||
// Open реализует метод http.FileSystem.
|
||||
func (f *HttpFS) Open(name string) (http.File, error) {
|
||||
name = strings.TrimPrefix(name, "/")
|
||||
if f.remoteStorage != nil {
|
||||
@@ -51,7 +52,7 @@ func (f *HttpFS) Open(name string) (http.File, error) {
|
||||
return f.localStorage.Open(name)
|
||||
}
|
||||
|
||||
// Remove
|
||||
// Remove удаляет файл.
|
||||
func (f *HttpFS) Remove(name string) error {
|
||||
name = strings.TrimPrefix(name, "/")
|
||||
if f.remoteStorage != nil {
|
||||
@@ -60,8 +61,8 @@ func (f *HttpFS) Remove(name string) error {
|
||||
return f.localStorage.Remove(name)
|
||||
}
|
||||
|
||||
// LocalStorage
|
||||
// LocalStorage возвращает указатель на локальное хранилище.
|
||||
func (f *HttpFS) LocalStorage() *LocalStorage { return f.localStorage }
|
||||
|
||||
// RemoteStorage
|
||||
// RemoteStorage возвращает указатель на удалённое хранилище.
|
||||
func (f *HttpFS) RemoteStorage() remote.Storage { return f.remoteStorage }
|
||||
|
||||
Reference in New Issue
Block a user