Documentation
¶
Index ¶
- Constants
- type Backend
- type BackendConfig
- type CacheConfig
- type Client
- func (b *Client) Close()
- func (b *Client) DeleteFile(file_id string) (string, error)
- func (b *Client) DeleteFileContext(ctx context.Context, file_id string) (string, error)
- func (b *Client) DeleteFilePermanently(file_id string) (string, error)
- func (b *Client) DeleteFilePermanentlyContext(ctx context.Context, file_id string) (string, error)
- func (b *Client) DeleteFolder(folder_id string) (string, error)
- func (b *Client) DeleteFolderContext(ctx context.Context, folder_id string) (string, error)
- func (b *Client) DeleteFolderPermanently(user_id, folder_id string) (string, error)
- func (b *Client) DeleteFolderPermanentlyContext(ctx context.Context, user_id, folder_id string) (string, error)
- func (b *Client) GetFile(file_id string) (*model.FileModel, error)
- func (b *Client) GetFileContext(ctx context.Context, file_id string) (*model.FileModel, error)
- func (b *Client) GetFileStream(file_id string) (*model.FileModel, io.ReadCloser, error)
- func (b *Client) GetFileStreamContext(ctx context.Context, file_id string) (*model.FileModel, io.ReadCloser, error)
- func (b *Client) GetFolderWithContent(user_id, folder_id string) (*model.FolderModel, error)
- func (b *Client) GetFolderWithContentContext(ctx context.Context, user_id, folder_id string) (*model.FolderModel, error)
- func (b *Client) ListFiles(folder_id string) ([]model.FileModel, error)
- func (b *Client) ListFilesContext(ctx context.Context, folder_id string) ([]model.FileModel, error)
- func (b *Client) ListFilesMetadata(folder_id string) ([]model.FileModel, error)
- func (b *Client) ListFilesMetadataContext(ctx context.Context, folder_id string) ([]model.FileModel, error)
- func (b *Client) ListFolders(folder_id string) ([]model.FolderModel, error)
- func (b *Client) ListFoldersContext(ctx context.Context, folder_id string) ([]model.FolderModel, error)
- func (b *Client) MoveFile(file_id string, new_parent_id string) error
- func (b *Client) MoveFileContext(ctx context.Context, file_id string, new_parent_id string) error
- func (b *Client) MoveFolder(user_id, folder_id string, new_parent_id string) error
- func (b *Client) MoveFolderContext(ctx context.Context, user_id, folder_id string, new_parent_id string) error
- func (b *Client) NewFolder(user_id string, parent_id string, folder_name string, description string) (new_folder_id string, err error)
- func (b *Client) NewFolderContext(ctx context.Context, user_id string, parent_id string, folder_name string, ...) (new_folder_id string, err error)
- func (b *Client) RenameFolder(user_id, folder_id string, new_name string) error
- func (b *Client) RenameFolderContext(ctx context.Context, user_id, folder_id string, new_name string) error
- func (b *Client) UploadFile(user_id string, parent_id string, file_name string, content_type string, ...) (string, error)
- func (b *Client) UploadFileContext(ctx context.Context, user_id string, parent_id string, file_name string, ...) (string, error)
- func (b *Client) UploadFileFromReader(user_id string, parent_id string, file_name string, content_type string, ...) (string, error)
- func (b *Client) UploadFileFromReaderContext(ctx context.Context, user_id string, parent_id string, file_name string, ...) (string, error)
- type Config
- type ConfigFunc
- func EnableMigration() ConfigFunc
- func FlatNameSpaces(flat bool) ConfigFunc
- func MediaDir(mediaDir string) ConfigFunc
- func RegisterPrimaryBackend(backend Backend) ConfigFunc
- func RegisterSecondaryBackend(backend Backend) ConfigFunc
- func WithCache(cache CacheConfig) ConfigFunc
- func WithDB(driver DBDrivers, db *sql.DB) ConfigFunc
- func WithLog(log LogConfig) ConfigFunc
- type DBConfig
- type DBDrivers
- type FileCacheConfig
- type FileInfo
- type LogConfig
Constants ¶
const ( // Posstgres represents the Postgres database driver. Postgres = model.Postgres // SQLite represents the SQLite database driver. SQLite = model.SQLite )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Backend ¶ added in v1.2.0
type Backend = domain.FileBackend
Backend represents the file backend interface.
It defines methods for interacting with the file storage backend.
func LocalBackend ¶ added in v1.2.0
func LocalBackend() Backend
LocalBackend is a placeholder and is replaced with the actual local backend implementation.
Usecase: Selecting the local backend for migration.
backendConfig := BackendConfig{
MigrationEnabled: true,
Source: buckt.LocalBackend(),
Target: aws.S3Backend(),
}
type BackendConfig ¶ added in v1.2.0
type BackendConfig struct {
// Source is the current backend in use (e.g., local, S3).
Source Backend
// Target is the backup or primary backend to migrate to (e.g., S3, Azure).
// If MigrationEnabled is false, this is ignored.
Target Backend
// MigrationEnabled enables dual-write migration mode.
MigrationEnabled bool
}
BackendConfig holds the configuration for the file backend.
It includes the source and target backends for migration.
If only one backend is specified, it is used as the primary backend.
type CacheConfig ¶ added in v1.0.2
type CacheConfig struct {
Manager domain.CacheManager
FileCacheConfig
}
CacheConfig holds the configuration for the cache manager. It includes the cache manager instance and file cache configuration. Fields:
Manager: The cache manager instance. FileCacheConfig: The file cache configuration.
type Client ¶ added in v1.2.0
type Client struct {
// contains filtered or unexported fields
}
func Default ¶
func Default(opts ...ConfigFunc) (*Client, error)
Default initializes a new Buckt Client with default configuration options. It accepts a variadic number of ConfigFunc options to customize the BucktConfig.
The default configuration includes: - LogConfig with LogTerminal set to true, LogFile set to "logs", and Debug set to true. - MediaDir set to "media". - FlatNameSpaces set to true.
Parameters: - opts: A variadic number of ConfigFunc options to customize the BucktConfig.
Returns: - A pointer to the initialized Buckt Client. - An error if the Buckt Client could not be created.
func New ¶
func New(conf Config, opts ...ConfigFunc) (*Client, error)
New initializes a new Buckt client with the provided configuration options. It accepts a Config struct and a variadic number of ConfigFunc options as arguments and returns a pointer to the initialized Buckt client.
Parameters: - conf: A Config struct containing the configuration options for the Buckt client. - opts: A variadic number of ConfigFunc options to customize the BucktConfig.
Returns: - A pointer to the initialized Buckt Client. - An error if the Buckt client could not be created.
func (*Client) Close ¶ added in v1.2.0
func (b *Client) Close()
Close closes the Buckt instance. It closes the database connection and the LRU cache.
func (*Client) DeleteFile ¶ added in v1.2.0
DeleteFile deletes a file associated with the given user ID and file ID. It returns an error if the deletion fails.
Parameters:
- file_id: The ID of the file to be deleted.
Returns:
- error: An error if the file deletion fails, otherwise nil.
func (*Client) DeleteFileContext ¶ added in v1.4.0
DeleteFileContext deletes a file associated with the given user ID and file ID. It returns an error if the deletion fails.
Parameters:
- ctx: The context for the operation.
- file_id: The ID of the file to be deleted.
Returns:
- error: An error if the file deletion fails, otherwise nil.
func (*Client) DeleteFilePermanently ¶ added in v1.2.0
DeleteFilePermanently deletes a file associated with the given user ID and file ID. It returns an error if the deletion fails.
Parameters:
- file_id: The ID of the file to be deleted.
Returns:
- error: An error if the file deletion fails, otherwise nil.
func (*Client) DeleteFilePermanentlyContext ¶ added in v1.4.0
DeleteFilePermanentlyContext deletes a file associated with the given user ID and file ID. It returns an error if the deletion fails.
Parameters:
- ctx: The context for the operation.
- file_id: The ID of the file to be deleted.
Returns:
- error: An error if the file deletion fails, otherwise nil.
func (*Client) DeleteFolder ¶ added in v1.2.0
DeleteFolder soft deletes a folder with the given folder_id using the folderService. It returns an error if the deletion fails.
Parameters:
- folder_id: The ID of the folder to be deleted.
Returns:
- error: An error if the deletion fails, otherwise nil.
func (*Client) DeleteFolderContext ¶ added in v1.4.0
DeleteFolderContext soft deletes a folder with the given folder_id using the folderService. It returns an error if the deletion fails.
Parameters:
- ctx: The context for the operation.
- folder_id: The ID of the folder to be deleted.
Returns:
- error: An error if the deletion fails, otherwise nil.
func (*Client) DeleteFolderPermanently ¶ added in v1.2.0
DeleteFolderPermanently deletes a folder permanently for a given user. It takes the user ID and folder ID as parameters and returns an error if the operation fails.
Parameters:
- user_id: The ID of the user who owns the folder.
- folder_id: The ID of the folder to be deleted.
Returns:
- error: An error object if the deletion fails, otherwise nil.
func (*Client) DeleteFolderPermanentlyContext ¶ added in v1.4.0
func (b *Client) DeleteFolderPermanentlyContext(ctx context.Context, user_id, folder_id string) (string, error)
DeleteFolderPermanentlyContext deletes a folder permanently for a given user. It takes the user ID and folder ID as parameters and returns an error if the operation fails.
Parameters:
- ctx: The context for the operation.
- user_id: The ID of the user who owns the folder.
- folder_id: The ID of the folder to be deleted.
Returns:
- error: An error object if the deletion fails, otherwise nil.
func (*Client) GetFile ¶ added in v1.2.0
GetFile retrieves a file based on the provided file ID. It returns the file data and an error, if any occurred during the retrieval process.
Parameters:
- file_id: A string representing the unique identifier of the file to be retrieved.
Returns:
- *model.FileModel: The file data.
- error: An error object if an error occurred, otherwise nil.
func (*Client) GetFileContext ¶ added in v1.4.0
GetFileContext retrieves a file based on the provided file ID. It returns the file data and an error, if any occurred during the retrieval process.
Parameters:
- ctx: The context for the operation.
- file_id: A string representing the unique identifier of the file to be retrieved.
Returns:
- *model.FileModel: The file data.
- error: An error object if an error occurred, otherwise nil.
func (*Client) GetFileStream ¶ added in v1.2.0
GetFileStream retrieves a file stream based on the provided file ID. It returns the file data and an error, if any occurred during the retrieval process.
Parameters:
- file_id: A string representing the unique identifier of the file to be retrieved.
Returns:
- *model.FileModel: The file structure containing metadata.
- io.ReadCloser: An io.ReadCloser object representing the file stream
- error: An error object if an error occurred, otherwise nil.
Note: The caller is responsible for closing the file stream after reading.
func (*Client) GetFileStreamContext ¶ added in v1.4.0
func (b *Client) GetFileStreamContext(ctx context.Context, file_id string) (*model.FileModel, io.ReadCloser, error)
GetFileStreamContext retrieves a file stream based on the provided file ID. It returns the file data and an error, if any occurred during the retrieval process.
Parameters:
- ctx: The context for the operation.
- file_id: A string representing the unique identifier of the file to be retrieved.
Returns:
- *model.FileModel: The file structure containing metadata.
- io.ReadCloser: An io.ReadCloser object representing the file stream
- error: An error object if an error occurred, otherwise nil.
Note: The caller is responsible for closing the file stream after reading.
func (*Client) GetFolderWithContent ¶ added in v1.2.0
func (b *Client) GetFolderWithContent(user_id, folder_id string) (*model.FolderModel, error)
GetFolderWithContent retrieves a folder and its content.
Parameters:
- user_id: The ID of the user who owns the folder.
- folder_id: The ID of the folder to retrieve the content for.
Returns:
- *model.FolderModel: The folder model containing the folder content.
- error: An error if the folder content could not be retrieved.
func (*Client) GetFolderWithContentContext ¶ added in v1.4.0
func (b *Client) GetFolderWithContentContext(ctx context.Context, user_id, folder_id string) (*model.FolderModel, error)
GetFolderWithContentContext retrieves a folder and its content.
Parameters:
- ctx: The context for the operation.
- user_id: The ID of the user who owns the folder.
- folder_id: The ID of the folder to retrieve the content for.
Returns:
- *model.FolderModel: The folder model containing the folder content.
- error: An error if the folder content could not be retrieved.
func (*Client) ListFiles ¶ added in v1.2.0
ListFiles retrieves a list of files for a given folder.
Parameters:
- folder_id: The ID of the folder to retrieve.
Returns:
- []model.FileModel: A list of files.
- error: An error if the folder could not be retrieved.
func (*Client) ListFilesContext ¶ added in v1.4.0
ListFilesContext retrieves a list of files for a given folder.
Parameters:
- ctx: The context for the operation.
- folder_id: The ID of the folder to retrieve.
Returns:
- []model.FileModel: A list of files.
- error: An error if the folder could not be retrieved.
func (*Client) ListFilesMetadata ¶ added in v1.4.1
ListFilesMetadata retrieves a list of files' metadata for a given folder.
Parameters:
- folder_id: The ID of the folder to retrieve.
Returns:
- []model.FileModel: A list of files' metadata.
- error: An error if the folder could not be retrieved.
func (*Client) ListFilesMetadataContext ¶ added in v1.4.1
func (b *Client) ListFilesMetadataContext(ctx context.Context, folder_id string) ([]model.FileModel, error)
ListFilesMetadataContext retrieves a list of files' metadata for a given folder.
Parameters:
- ctx: The context for the operation.
- folder_id: The ID of the folder to retrieve.
Returns:
- []model.FileModel: A list of files' metadata.
- error: An error if the folder could not be retrieved.
func (*Client) ListFolders ¶ added in v1.2.0
func (b *Client) ListFolders(folder_id string) ([]model.FolderModel, error)
ListFolders retrieves a list of folders for a given folder.
Parameters:
- folder_id: The ID of the folder to retrieve.
Returns:
- []model.FolderModel: A list of folders.
- error: An error if the folder could not be retrieved.
func (*Client) ListFoldersContext ¶ added in v1.4.0
func (b *Client) ListFoldersContext(ctx context.Context, folder_id string) ([]model.FolderModel, error)
ListFoldersContext retrieves a list of folders for a given folder.
Parameters:
- ctx: The context for the operation.
- folder_id: The ID of the folder to retrieve.
Returns:
- []model.FolderModel: A list of folders.
- error: An error if the folder could not be retrieved.
func (*Client) MoveFile ¶ added in v1.2.0
MoveFile moves a file to a new parent directory.
Parameters:
- file_id: The ID of the file to be updated.
- new_parent_id: The new parent directory for the file.
Returns:
- error: An error if the update operation fails, otherwise nil.
func (*Client) MoveFileContext ¶ added in v1.4.0
MoveFileContext moves a file to a new parent directory.
Parameters:
- ctx: The context for the operation.
- file_id: The ID of the file to be updated.
- new_parent_id: The new parent directory for the file.
Returns:
- error: An error if the update operation fails, otherwise nil.
func (*Client) MoveFolder ¶ added in v1.2.0
MoveFolder moves a folder to a new parent folder.
Parameters:
- user_id: The ID of the user performing the operation.
- folder_id: The ID of the folder to be moved.
- new_parent_id: The ID of the new parent folder.
Returns:
- error: An error if the operation fails, otherwise nil.
func (*Client) MoveFolderContext ¶ added in v1.4.0
func (b *Client) MoveFolderContext(ctx context.Context, user_id, folder_id string, new_parent_id string) error
MoveFolderContext moves a folder to a new parent folder.
Parameters:
- ctx: The context for the operation.
- user_id: The ID of the user performing the operation.
- folder_id: The ID of the folder to be moved.
- new_parent_id: The ID of the new parent folder.
Returns:
- error: An error if the operation fails, otherwise nil.
func (*Client) NewFolder ¶ added in v1.2.0
func (b *Client) NewFolder(user_id string, parent_id string, folder_name string, description string) (new_folder_id string, err error)
NewFolder creates a new folder for a user within a specified parent folder.
Parameters:
- user_id: The ID of the user creating the folder.
- parent_id: The ID of the parent folder where the new folder will be created.
- folder_name: The name of the new folder.
- description: A description of the new folder.
Returns:
- The ID of the newly created folder.
- An error if the operation fails.
func (*Client) NewFolderContext ¶ added in v1.4.0
func (b *Client) NewFolderContext(ctx context.Context, user_id string, parent_id string, folder_name string, description string) (new_folder_id string, err error)
NewFolderContext creates a new folder for a user within a specified parent folder.
Parameters:
- ctx: The context for the operation.
- user_id: The ID of the user creating the folder.
- parent_id: The ID of the parent folder where the new folder will be created.
- folder_name: The name of the new folder.
- description: A description of the new folder.
Returns:
- The ID of the newly created folder.
- An error if the operation fails.
func (*Client) RenameFolder ¶ added in v1.2.0
RenameFolder renames a folder.
Parameters:
- user_id: The ID of the user performing the operation.
- folder_id: The ID of the folder to be renamed.
- new_name: The new name for the folder.
Returns:
- error: An error if the operation fails, otherwise nil.
func (*Client) RenameFolderContext ¶ added in v1.4.0
func (b *Client) RenameFolderContext(ctx context.Context, user_id, folder_id string, new_name string) error
RenameFolderContext renames a folder.
Parameters:
- ctx: The context for the operation.
- user_id: The ID of the user performing the operation.
- folder_id: The ID of the folder to be renamed.
- new_name: The new name for the folder.
Returns:
- error: An error if the operation fails, otherwise nil.
func (*Client) UploadFile ¶ added in v1.2.0
func (b *Client) UploadFile(user_id string, parent_id string, file_name string, content_type string, file_data []byte) (string, error)
UploadFile uploads a file to the specified user's bucket.
Parameters:
- user_id: The ID of the user who owns the bucket.
- parent_id: The ID of the parent directory where the file will be uploaded.
- file_name: The name of the file to be uploaded.
- content_type: The MIME type of the file.
- file_data: The byte slice containing the file data.
Returns:
- string: The ID of the newly created file.
- error: An error if the file upload fails, otherwise nil.
func (*Client) UploadFileContext ¶ added in v1.4.0
func (b *Client) UploadFileContext(ctx context.Context, user_id string, parent_id string, file_name string, content_type string, file_data []byte) (string, error)
UploadFileContext uploads a file to the specified user's bucket.
Parameters:
- ctx: The context for the operation.
- user_id: The ID of the user who owns the bucket.
- parent_id: The ID of the parent directory where the file will be uploaded.
- file_name: The name of the file to be uploaded.
- content_type: The MIME type of the file.
- file_data: The byte slice containing the file data.
Returns:
- string: The ID of the newly created file.
- error: An error if the file upload fails, otherwise nil.
func (*Client) UploadFileFromReader ¶ added in v1.4.0
func (b *Client) UploadFileFromReader(user_id string, parent_id string, file_name string, content_type string, file_data io.Reader) (string, error)
UploadFileFromReader uploads a file to the specified user's bucket from an io.Reader.
Parameters:
- user_id: The ID of the user who owns the bucket.
- parent_id: The ID of the parent directory where the file will be uploaded.
- file_name: The name of the file to be uploaded.
- content_type: The MIME type of the file.
- file_data: An io.Reader containing the file data.
Returns:
- string: The ID of the newly created file.
- error: An error if the file upload fails, otherwise nil.
func (*Client) UploadFileFromReaderContext ¶ added in v1.4.0
func (b *Client) UploadFileFromReaderContext(ctx context.Context, user_id string, parent_id string, file_name string, content_type string, file_data io.Reader) (string, error)
UploadFileFromReaderContext uploads a file to the specified user's bucket from an io.Reader.
Parameters:
- ctx: The context for the operation.
- user_id: The ID of the user who owns the bucket.
- parent_id: The ID of the parent directory where the file will be uploaded.
- file_name: The name of the file to be uploaded.
- content_type: The MIME type of the file.
- file_data: An io.Reader containing the file data.
Returns:
- string: The ID of the newly created file.
- error: An error if the file upload fails, otherwise nil.
type Config ¶ added in v1.2.0
type Config struct {
MediaDir string
FlatNameSpaces bool
DB DBConfig
Cache CacheConfig
Log LogConfig
Backend BackendConfig
}
Config represents the configuration options for the Buckt application. It includes settings for logging, media directory, and standalone mode.
Fields:
DB: Database configuration. Cache: Cache configuration. Log: Configuration for logging. MediaDir: Path to the directory where media files are stored. FlatNameSpaces: Flag indicating whether the application should use flat namespaces when storing files.
type ConfigFunc ¶
type ConfigFunc func(*Config)
ConfigFunc is a function type that takes a pointer to Config and modifies it.
func EnableMigration ¶ added in v1.4.0
func EnableMigration() ConfigFunc
EnableMigration enables dual-write migration mode in the Buckt application.
func FlatNameSpaces ¶
func FlatNameSpaces(flat bool) ConfigFunc
FlatNameSpaces is a configuration function that sets the FlatNameSpaces option in the Config. When the flat parameter is true, it enables flat namespaces; otherwise, it disables them.
Parameters:
flat - a boolean value indicating whether to enable or disable flat namespaces.
Returns:
A ConfigFunc that applies the flat namespaces setting to a Config.
func MediaDir ¶
func MediaDir(mediaDir string) ConfigFunc
MediaDir sets the directory path for media files in the Config. It takes a string parameter mediaDir which specifies the path to the media directory. It returns a ConfigFunc that updates the MediaDir field of Config.
func RegisterPrimaryBackend ¶ added in v1.2.0
func RegisterPrimaryBackend(backend Backend) ConfigFunc
RegisterPrimaryBackend registers the primary backend for the Buckt application.
func RegisterSecondaryBackend ¶ added in v1.2.0
func RegisterSecondaryBackend(backend Backend) ConfigFunc
RegisterSecondaryBackend registers the secondary backend for the Buckt application.
func WithCache ¶
func WithCache(cache CacheConfig) ConfigFunc
WithCache is a configuration function that sets the cache configuration for the Config. It takes a CacheConfig instance as an argument and assigns it to the Cache field of Config.
Parameters:
- cache: An instance of CacheConfig to be used for caching.
Returns:
- A ConfigFunc that sets the CacheManager in the Config.
func WithDB ¶
func WithDB(driver DBDrivers, db *sql.DB) ConfigFunc
WithDB is a configuration function that sets the database connection for the Config. It takes a *sql.DB as an argument and returns a ConfigFunc that assigns the provided database connection to the Config.
Parameters:
- driver: A string representing the database driver name.
- db: A pointer to an sql.DB instance representing the database connection.
Returns:
- ConfigFunc: A function that takes a pointer to Config and sets its DB field.
func WithLog ¶
func WithLog(log LogConfig) ConfigFunc
WithLog is a configuration function that sets the logger for the Config. It takes a Log instance as an argument and assigns it to the Log field of Config.
Parameters:
- log: An instance of Log to be used for logging.
Returns:
- A ConfigFunc that sets the Log field of Config.
type DBConfig ¶
DBConfig holds the configuration for the database connection.
Fields:
Driver: A string representing the database driver name. Database: A pointer to an sql.DB instance representing the database connection.
type FileCacheConfig ¶ added in v1.0.2
FileCacheConfig holds the configuration for the file cache. It includes settings for the number of counters, maximum cost, and buffer items.
Fields:
NumCounters: The number of counters for the cache. MaxCost: The maximum cost of the cache. BufferItems: The number of items in the buffer.
func (*FileCacheConfig) Validate ¶ added in v1.0.2
func (f *FileCacheConfig) Validate()
Validate checks the configuration values for the file cache. It sets default values if the provided values are less than or equal to zero. The default values are:
NumCounters: 1e7 (10 million) MaxCost: 1 << 30 (1 GB) BufferItems: 64
If the values are already set to valid values, they remain unchanged. This function is useful for ensuring that the cache configuration is valid before using it in the application. It is typically called during the initialization of the cache manager.
type LogConfig ¶
LogConfig holds the configuration for logging in the application.
Fields:
LogFile: A string representing the log file path. Silence: A boolean flag indicating whether to silence logs. LogTerminal: A boolean flag indicating whether to log to the terminal. Logger: A pointer to a log.Logger instance. If nil, a new logger will be created.