storage

package
v1.26.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 18, 2026 License: MIT Imports: 26 Imported by: 27

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrURLNotSupported = errors.New("url method not supported")

ErrURLNotSupported represents url is not supported

Functions

func Clean added in v1.15.0

func Clean(storage ObjectStorage) error

Clean delete all the objects in this storage

func Copy

func Copy(dstStorage ObjectStorage, dstPath string, srcStorage ObjectStorage, srcPath string) (int64, error)

Copy copies a file from source ObjectStorage to dest ObjectStorage

func Init

func Init() error

Init init the storage

func IsErrInvalidConfiguration

func IsErrInvalidConfiguration(err error) bool

IsErrInvalidConfiguration checks if an error is an ErrInvalidConfiguration

func RegisterStorageType

func RegisterStorageType(typ Type, fn func(ctx context.Context, cfg *setting.Storage) (ObjectStorage, error))

RegisterStorageType registers a provided storage type with a function to create it

func SaveFrom

func SaveFrom(objStorage ObjectStorage, path string, callback func(w io.Writer) error) error

SaveFrom saves data to the ObjectStorage with path p from the callback

Types

type AzureBlobStorage added in v1.23.0

type AzureBlobStorage struct {
	// contains filtered or unexported fields
}

AzureStorage returns a azure blob storage

func (*AzureBlobStorage) Delete added in v1.23.0

func (a *AzureBlobStorage) Delete(path string) error

Delete delete a file

func (*AzureBlobStorage) IterateObjects added in v1.23.0

func (a *AzureBlobStorage) IterateObjects(dirName string, fn func(path string, obj Object) error) error

IterateObjects iterates across the objects in the azureblobstorage

func (*AzureBlobStorage) Open added in v1.23.0

func (a *AzureBlobStorage) Open(path string) (Object, error)

Open opens a file

func (*AzureBlobStorage) Save added in v1.23.0

func (a *AzureBlobStorage) Save(path string, r io.Reader, size int64) (int64, error)

Save saves a file to azure blob storage

func (*AzureBlobStorage) ServeDirectURL added in v1.26.0

func (a *AzureBlobStorage) ServeDirectURL(storePath, name, method string, reqParams *ServeDirectOptions) (*url.URL, error)

func (*AzureBlobStorage) Stat added in v1.23.0

func (a *AzureBlobStorage) Stat(path string) (os.FileInfo, error)

Stat returns the stat information of the object

type ErrInvalidConfiguration

type ErrInvalidConfiguration struct {
	// contains filtered or unexported fields
}

ErrInvalidConfiguration is called when there is invalid configuration for a storage

func (ErrInvalidConfiguration) Error

func (err ErrInvalidConfiguration) Error() string

type LocalStorage

type LocalStorage struct {
	// contains filtered or unexported fields
}

LocalStorage represents a local files storage

func (*LocalStorage) Delete

func (l *LocalStorage) Delete(path string) error

Delete deletes the file in storage and removes the empty parent directories (if possible)

func (*LocalStorage) IterateObjects

func (l *LocalStorage) IterateObjects(dirName string, fn func(path string, obj Object) error) error

IterateObjects iterates across the objects in the local storage

func (*LocalStorage) Open

func (l *LocalStorage) Open(path string) (Object, error)

Open a file

func (*LocalStorage) Save

func (l *LocalStorage) Save(path string, r io.Reader, size int64) (int64, error)

Save a file

func (*LocalStorage) ServeDirectURL added in v1.26.0

func (l *LocalStorage) ServeDirectURL(path, name, _ string, reqParams *ServeDirectOptions) (*url.URL, error)

func (*LocalStorage) Stat

func (l *LocalStorage) Stat(path string) (os.FileInfo, error)

Stat returns the info of the file

type MinioStorage

type MinioStorage struct {
	// contains filtered or unexported fields
}

MinioStorage returns a minio bucket storage

func (*MinioStorage) Delete

func (m *MinioStorage) Delete(path string) error

Delete delete a file

func (*MinioStorage) IterateObjects

func (m *MinioStorage) IterateObjects(dirName string, fn func(path string, obj Object) error) error

IterateObjects iterates across the objects in the miniostorage

func (*MinioStorage) Open

func (m *MinioStorage) Open(path string) (Object, error)

Open opens a file

func (*MinioStorage) Save

func (m *MinioStorage) Save(path string, r io.Reader, size int64) (int64, error)

Save saves a file to minio

func (*MinioStorage) ServeDirectURL added in v1.26.0

func (m *MinioStorage) ServeDirectURL(storePath, name, method string, opt *ServeDirectOptions) (*url.URL, error)

func (*MinioStorage) Stat

func (m *MinioStorage) Stat(path string) (os.FileInfo, error)

Stat returns the stat information of the object

type NewStorageFunc

type NewStorageFunc func(ctx context.Context, cfg *setting.Storage) (ObjectStorage, error)

NewStorageFunc is a function that creates a storage

type Object

type Object interface {
	io.ReadCloser
	io.Seeker
	Stat() (os.FileInfo, error)
}

Object represents the object on the storage

type ObjectStorage

type ObjectStorage interface {
	Open(path string) (Object, error)

	// Save store an object, if size is unknown set -1
	// NOTICE: Some storage SDK will close the Reader after saving if it is also a Closer,
	// DO NOT use the reader anymore after Save, or wrap it to a non-Closer reader.
	Save(path string, r io.Reader, size int64) (int64, error)

	Stat(path string) (os.FileInfo, error)
	Delete(path string) error

	// ServeDirectURL generates a "serve-direct" URL for the specified blob storage file,
	// end user (browser) will use this URL to access the file directly from the object storage, bypassing Gitea server.
	// Usually the link is time-limited (a few minutes) and contains a signature to ensure security.
	// The generated URL must NOT use the same origin as Gitea server, otherwise it will cause security issues.
	// * method defines which HTTP method is permitted for certain storage providers (e.g., MinIO).
	// * opt allows customizing the Content-Type and Content-Disposition headers.
	// TODO: need to merge "ServeDirect()" check into this function, avoid duplicate code and potential inconsistency.
	ServeDirectURL(path, name, method string, opt *ServeDirectOptions) (*url.URL, error)

	// IterateObjects calls the iterator function for each object in the storage with the given path as prefix
	// The "fullPath" argument in callback is the full path in this storage.
	// * IterateObjects("", ...): iterate all objects in this storage
	// * IterateObjects("sub-path", ...): iterate all objects with "sub-path" as prefix in this storage, the "fullPath" will be like "sub-path/xxx"
	IterateObjects(basePath string, iterator func(fullPath string, obj Object) error) error
}

ObjectStorage represents an object storage to handle a bucket and files

var (
	// Attachments represents attachments storage
	Attachments ObjectStorage = uninitializedStorage

	// LFS represents lfs storage
	LFS ObjectStorage = uninitializedStorage

	// Avatars represents user avatars storage
	Avatars ObjectStorage = uninitializedStorage
	// RepoAvatars represents repository avatars storage
	RepoAvatars ObjectStorage = uninitializedStorage

	// RepoArchives represents repository archives storage
	RepoArchives ObjectStorage = uninitializedStorage

	// Packages represents packages storage
	Packages ObjectStorage = uninitializedStorage

	// Actions represents actions storage
	Actions ObjectStorage = uninitializedStorage
	// ActionsArtifacts Artifacts represents actions artifacts storage
	ActionsArtifacts ObjectStorage = uninitializedStorage
)

func NewAzureBlobStorage added in v1.23.0

func NewAzureBlobStorage(ctx context.Context, cfg *setting.Storage) (ObjectStorage, error)

NewAzureBlobStorage returns a azure blob storage

func NewLocalStorage

func NewLocalStorage(ctx context.Context, config *setting.Storage) (ObjectStorage, error)

NewLocalStorage returns a local files

func NewMinioStorage

func NewMinioStorage(ctx context.Context, cfg *setting.Storage) (ObjectStorage, error)

NewMinioStorage returns a minio storage

func NewStorage

func NewStorage(typStr Type, cfg *setting.Storage) (ObjectStorage, error)

NewStorage takes a storage type and some config and returns an ObjectStorage or an error

type ServeDirectOptions added in v1.26.0

type ServeDirectOptions struct {
	// Overrides the automatically detected MIME type.
	ContentType string
}

ServeDirectOptions customizes HTTP headers for a generated signed URL.

type Type

type Type = setting.StorageType

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL