-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add filestorage, update interface, fix typo error (#46)
* Add filestorage, update interface, fix typo error
- Loading branch information
Showing
8 changed files
with
108 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
package config | ||
|
||
type Proxy struct { | ||
ConsolePort string `json:"console_port" toml:"console+port" yaml:"console_port"` | ||
ConsolePort string `json:"console_port" toml:"console_port" yaml:"console_port"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package storage | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"io/fs" | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/yezzey-gp/yproxy/config" | ||
) | ||
|
||
// Storage prefix uses as path to folder. | ||
// "/path/to/folder/" + "path/to/file.txt" | ||
type FileStorageInteractor struct { | ||
StorageInteractor | ||
cnf *config.Storage | ||
} | ||
|
||
func (s *FileStorageInteractor) CatFileFromStorage(name string, offset int64) (io.ReadCloser, error) { | ||
file, err := os.Open(s.cnf.StoragePrefix + name) | ||
if err != nil { | ||
return nil, err | ||
} | ||
_, err = io.CopyN(io.Discard, file, offset) | ||
return file, err | ||
} | ||
func (s *FileStorageInteractor) ListPath(prefix string) ([]*ObjectInfo, error) { | ||
var data []*ObjectInfo | ||
err := filepath.WalkDir(s.cnf.StoragePrefix+prefix, func(path string, d fs.DirEntry, err error) error { | ||
if err != nil { | ||
return err | ||
} | ||
if d.IsDir() { | ||
return nil | ||
} | ||
file, err := os.Open(path) | ||
if err != nil { | ||
return err | ||
} | ||
fileinfo, err := file.Stat() | ||
if err != nil { | ||
return err | ||
} | ||
data = append(data, &ObjectInfo{fileinfo.Name(), fileinfo.Size()}) | ||
return nil | ||
}) | ||
return data, err | ||
} | ||
|
||
func (s *FileStorageInteractor) PutFileToDest(name string, r io.Reader) error { | ||
file, err := os.Create(s.cnf.StoragePrefix + name) | ||
if err != nil { | ||
return err | ||
} | ||
_, err = io.Copy(file, r) | ||
return err | ||
} | ||
|
||
func (s *FileStorageInteractor) PatchFile(name string, r io.ReadSeeker, startOffset int64) error { | ||
//UNUSED TODO | ||
return fmt.Errorf("TODO") | ||
} | ||
|
||
func (s *FileStorageInteractor) MoveObject(from string, to string) error { | ||
return os.Rename(s.cnf.StoragePrefix+from, s.cnf.StoragePrefix+to) | ||
} | ||
|
||
func (s *FileStorageInteractor) DeleteObject(key string) error { | ||
return os.Remove(s.cnf.StoragePrefix + key) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters