1a56070556
- Introduced a comprehensive MinIO package for managing object storage, including support for hierarchical document storage and general file management. - Implemented core components such as Config, ConnectionManager, and Service, following Clean Architecture principles. - Added functionality for file uploads, downloads, bucket management, and structured logging, enhancing usability and maintainability. - Included detailed error handling and validation for configuration and operations, ensuring robustness. - Updated documentation with usage examples and configuration guidelines to facilitate integration and understanding of the package's functionality.
77 lines
2.7 KiB
Go
77 lines
2.7 KiB
Go
package minio
|
|
|
|
import "time"
|
|
|
|
// Config holds MinIO connection configuration
|
|
type Config struct {
|
|
Endpoint string `json:"endpoint" yaml:"endpoint"`
|
|
AccessKeyID string `json:"accessKeyID" yaml:"accessKeyID"`
|
|
SecretAccessKey string `json:"secretAccessKey" yaml:"secretAccessKey"`
|
|
UseSSL bool `json:"useSSL" yaml:"useSSL"`
|
|
Region string `json:"region" yaml:"region"`
|
|
|
|
// Connection settings
|
|
ConnectTimeout time.Duration `json:"connectTimeout" yaml:"connectTimeout"`
|
|
RequestTimeout time.Duration `json:"requestTimeout" yaml:"requestTimeout"`
|
|
|
|
// Bucket settings
|
|
DefaultBucket string `json:"defaultBucket" yaml:"defaultBucket"`
|
|
|
|
// Hierarchical storage settings
|
|
HierarchicalBucket string `json:"hierarchicalBucket" yaml:"hierarchicalBucket"`
|
|
PathSeparator string `json:"pathSeparator" yaml:"pathSeparator"`
|
|
|
|
// Upload settings
|
|
MaxFileSize int64 `json:"maxFileSize" yaml:"maxFileSize"` // Maximum file size in bytes
|
|
AllowedTypes []string `json:"allowedTypes" yaml:"allowedTypes"` // Allowed MIME types
|
|
ChunkSize int64 `json:"chunkSize" yaml:"chunkSize"` // Chunk size for multipart uploads
|
|
}
|
|
|
|
// DefaultConfig returns a default MinIO configuration
|
|
func DefaultConfig() Config {
|
|
return Config{
|
|
UseSSL: true,
|
|
Region: "us-east-1",
|
|
ConnectTimeout: 10 * time.Second,
|
|
RequestTimeout: 30 * time.Second,
|
|
DefaultBucket: "files",
|
|
HierarchicalBucket: "documents",
|
|
PathSeparator: "/",
|
|
MaxFileSize: 100 * 1024 * 1024, // 100MB
|
|
AllowedTypes: []string{"*"}, // Allow all types by default
|
|
ChunkSize: 5 * 1024 * 1024, // 5MB chunks
|
|
}
|
|
}
|
|
|
|
// Validate validates the MinIO configuration
|
|
func (c *Config) Validate() error {
|
|
if c.Endpoint == "" {
|
|
return NewErrorWithCause(ErrCodeInvalidConfig, "endpoint is required", ErrInvalidConfig)
|
|
}
|
|
if c.AccessKeyID == "" {
|
|
return NewErrorWithCause(ErrCodeInvalidConfig, "accessKeyID is required", ErrInvalidConfig)
|
|
}
|
|
if c.SecretAccessKey == "" {
|
|
return NewErrorWithCause(ErrCodeInvalidConfig, "secretAccessKey is required", ErrInvalidConfig)
|
|
}
|
|
if c.DefaultBucket == "" {
|
|
return NewErrorWithCause(ErrCodeInvalidConfig, "defaultBucket is required", ErrInvalidConfig)
|
|
}
|
|
if c.HierarchicalBucket == "" {
|
|
return NewErrorWithCause(ErrCodeInvalidConfig, "hierarchicalBucket is required", ErrInvalidConfig)
|
|
}
|
|
if c.PathSeparator == "" {
|
|
c.PathSeparator = "/"
|
|
}
|
|
if c.MaxFileSize <= 0 {
|
|
c.MaxFileSize = 100 * 1024 * 1024 // 100MB default
|
|
}
|
|
if len(c.AllowedTypes) == 0 {
|
|
c.AllowedTypes = []string{"*"}
|
|
}
|
|
if c.ChunkSize <= 0 {
|
|
c.ChunkSize = 5 * 1024 * 1024 // 5MB default
|
|
}
|
|
return nil
|
|
}
|