diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2020-09-29 17:05:13 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-29 12:05:13 +0300 |
commit | 3878e985b66cc6d4cb4d2b0e7406d5cf91af6191 (patch) | |
tree | 31229c29c2b57041d1941ec28b043165cbe4642d /modules/storage/storage.go | |
parent | 4c6ac08182b5a14eaaffaafafef160bd90c4ae81 (diff) | |
download | gitea-3878e985b66cc6d4cb4d2b0e7406d5cf91af6191.tar.gz gitea-3878e985b66cc6d4cb4d2b0e7406d5cf91af6191.zip |
Add default storage configurations (#12813)
Signed-off-by: Andrew Thornton <art27@cantab.net>
Co-authored-by: zeripath <art27@cantab.net>
Diffstat (limited to 'modules/storage/storage.go')
-rw-r--r-- | modules/storage/storage.go | 68 |
1 files changed, 24 insertions, 44 deletions
diff --git a/modules/storage/storage.go b/modules/storage/storage.go index e355d2459f..2cf7b17b49 100644 --- a/modules/storage/storage.go +++ b/modules/storage/storage.go @@ -10,7 +10,7 @@ import ( "fmt" "io" "net/url" - "time" + "os" "code.gitea.io/gitea/modules/setting" ) @@ -18,28 +18,25 @@ import ( var ( // ErrURLNotSupported represents url is not supported ErrURLNotSupported = errors.New("url method not supported") + // ErrIterateObjectsNotSupported represents IterateObjects not supported + ErrIterateObjectsNotSupported = errors.New("iterateObjects method not supported") ) // Object represents the object on the storage type Object interface { io.ReadCloser io.Seeker -} - -// ObjectInfo represents the object info on the storage -type ObjectInfo interface { - Name() string - Size() int64 - ModTime() time.Time + Stat() (os.FileInfo, error) } // ObjectStorage represents an object storage to handle a bucket and files type ObjectStorage interface { Open(path string) (Object, error) Save(path string, r io.Reader) (int64, error) - Stat(path string) (ObjectInfo, error) + Stat(path string) (os.FileInfo, error) Delete(path string) error URL(path, name string) (*url.URL, error) + IterateObjects(func(path string, obj Object) error) error } // Copy copys a file from source ObjectStorage to dest ObjectStorage @@ -70,14 +67,15 @@ func Init() error { return initLFS() } -func initAttachments() error { +func initStorage(storageCfg setting.Storage) (ObjectStorage, error) { var err error - switch setting.Attachment.StoreType { - case "local": - Attachments, err = NewLocalStorage(setting.Attachment.Path) - case "minio": - minio := setting.Attachment.Minio - Attachments, err = NewMinioStorage( + var s ObjectStorage + switch storageCfg.Type { + case setting.LocalStorageType: + s, err = NewLocalStorage(storageCfg.Path) + case setting.MinioStorageType: + minio := storageCfg.Minio + s, err = NewMinioStorage( context.Background(), minio.Endpoint, minio.AccessKeyID, @@ -88,40 +86,22 @@ func initAttachments() error { minio.UseSSL, ) default: - return fmt.Errorf("Unsupported attachment store type: %s", setting.Attachment.StoreType) + return nil, fmt.Errorf("Unsupported attachment store type: %s", storageCfg.Type) } if err != nil { - return err + return nil, err } - return nil + return s, nil } -func initLFS() error { - var err error - switch setting.LFS.StoreType { - case "local": - LFS, err = NewLocalStorage(setting.LFS.ContentPath) - case "minio": - minio := setting.LFS.Minio - LFS, err = NewMinioStorage( - context.Background(), - minio.Endpoint, - minio.AccessKeyID, - minio.SecretAccessKey, - minio.Bucket, - minio.Location, - minio.BasePath, - minio.UseSSL, - ) - default: - return fmt.Errorf("Unsupported LFS store type: %s", setting.LFS.StoreType) - } - - if err != nil { - return err - } +func initAttachments() (err error) { + Attachments, err = initStorage(setting.Attachment.Storage) + return +} - return nil +func initLFS() (err error) { + LFS, err = initStorage(setting.LFS.Storage) + return } |