Documentation
¶
Index ¶
- Constants
- Variables
- func GetCopyBuffer(bufferSize int) []byte
- type LocalFS
- func (l *LocalFS) CreateFile(ctx context.Context, parentID, name string, size int64, ...) (types.File, error)
- func (l *LocalFS) CreateFolder(parentId, name string) (types.Folder, error)
- func (l *LocalFS) ListChildren(identifier string, depth *int, parentPath string) (types.ListResult, error)
- func (l *LocalFS) NormalizePath(path string) string
- func (l *LocalFS) OpenRead(ctx context.Context, fileID string) (io.ReadCloser, error)
- func (l *LocalFS) OpenWrite(ctx context.Context, fileID string) (io.WriteCloser, error)
- type ServiceManager
- func (m *ServiceManager) AcquireAdapter(def serviceDefinition, rootID, connectionID string) (types.FSAdapter, func(), error)
- func (m *ServiceManager) AcquireAdapterWithOverride(def serviceDefinition, rootID, connectionID, spectraConfigOverridePath string) (types.FSAdapter, func(), error)
- func (m *ServiceManager) GetServiceDefinition(id string) (types.ServiceDefinition, error)
- func (m *ServiceManager) GetServiceDefinitionByWorld(world string) (types.ServiceDefinition, error)
- func (m *ServiceManager) ListChildren(ctx context.Context, req types.ListChildrenRequest) (types.ListResult, types.PaginationInfo, error)
- func (m *ServiceManager) ListDrives(ctx context.Context, serviceID string) ([]types.DriveInfo, error)
- func (m *ServiceManager) ListSources(ctx context.Context) ([]types.Source, error)
- func (m *ServiceManager) LoadServices(localServices []types.LocalServiceConfig, ...) error
- func (m *ServiceManager) RegisterSpectraSession(configPath string, connectionID string) (string, error)
- func (m *ServiceManager) ReleaseConnection(connectionID string)
- type SpectraFS
- func (s *SpectraFS) CreateFile(ctx context.Context, parentID, name string, size int64, ...) (types.File, error)
- func (s *SpectraFS) CreateFolder(parentId, name string) (types.Folder, error)
- func (s *SpectraFS) GetSDKInstance() *sdk.SpectraFS
- func (s *SpectraFS) ListChildren(identifier string, depth *int, parentPath string) (types.ListResult, error)
- func (s *SpectraFS) NewChildrenPager(identifier string, pageSize int, depth *int, parentPath string) (*types.ListPager, error)
- func (s *SpectraFS) NormalizePath(path string) string
- func (s *SpectraFS) OpenRead(ctx context.Context, fileID string) (io.ReadCloser, error)
- func (s *SpectraFS) OpenWrite(ctx context.Context, fileID string) (io.WriteCloser, error)
- type SpectraSession
Constants ¶
const DefaultCopyBufferSize = 8 * 1024 * 1024 // 8MB
DefaultCopyBufferSize is the default buffer size used for io.CopyBuffer operations. This is set to 8MB, which is a good balance between memory usage and performance for most file copy operations. Industry standard is typically 1-64MB depending on use case, with 8MB being a common choice for general-purpose file operations.
Variables ¶
var ErrServiceNotFound = fmt.Errorf("service not found")
Functions ¶
func GetCopyBuffer ¶
GetCopyBuffer returns a buffer suitable for use with io.CopyBuffer. If bufferSize is 0 or negative, it uses DefaultCopyBufferSize (8MB). Otherwise, it uses the provided bufferSize.
Example usage:
buffer := fs.GetCopyBuffer(0) // Uses default 8MB defer bufferPool.Put(buffer) _, err := io.CopyBuffer(dstWriter, srcReader, buffer)
Or with custom size:
buffer := fs.GetCopyBuffer(64 * 1024 * 1024) // 64MB defer bufferPool.Put(buffer) _, err := io.CopyBuffer(dstWriter, srcReader, buffer)
Types ¶
type LocalFS ¶
type LocalFS struct {
// contains filtered or unexported fields
}
LocalFS implements FSAdapter for the local filesystem.
func NewLocalFS ¶
NewLocalFS constructs a new LocalFS adapter rooted at the given path.
func (*LocalFS) CreateFile ¶
func (l *LocalFS) CreateFile(ctx context.Context, parentID, name string, size int64, metadata map[string]string) (types.File, error)
CreateFile creates an empty file at the destination path with metadata. The file is created and immediately closed, ready for OpenWrite to open it for writing.
func (*LocalFS) CreateFolder ¶
CreateFolder creates a new folder under a parent absolute path.
func (*LocalFS) ListChildren ¶
func (l *LocalFS) ListChildren(identifier string, depth *int, parentPath string) (types.ListResult, error)
ListChildren lists immediate children of the given node identifier (absolute path). The depth and parentPath parameters are ignored for local filesystems.
func (*LocalFS) NormalizePath ¶
NormalizePath cleans and normalizes any incoming path string.
type ServiceManager ¶
type ServiceManager struct {
// contains filtered or unexported fields
}
ServiceManager handles service-related operations
func NewServiceManager ¶
func NewServiceManager() *ServiceManager
NewServiceManager creates a new ServiceManager instance
func (*ServiceManager) AcquireAdapter ¶
func (m *ServiceManager) AcquireAdapter(def serviceDefinition, rootID, connectionID string) (types.FSAdapter, func(), error)
AcquireAdapter acquires an adapter for the given service definition
func (*ServiceManager) AcquireAdapterWithOverride ¶
func (m *ServiceManager) AcquireAdapterWithOverride(def serviceDefinition, rootID, connectionID, spectraConfigOverridePath string) (types.FSAdapter, func(), error)
AcquireAdapterWithOverride acquires an adapter, with optional Spectra config override path
func (*ServiceManager) GetServiceDefinition ¶
func (m *ServiceManager) GetServiceDefinition(id string) (types.ServiceDefinition, error)
GetServiceDefinition returns a service definition by ID
func (*ServiceManager) GetServiceDefinitionByWorld ¶
func (m *ServiceManager) GetServiceDefinitionByWorld(world string) (types.ServiceDefinition, error)
GetServiceDefinitionByWorld finds the first Spectra service with the given world.
func (*ServiceManager) ListChildren ¶
func (m *ServiceManager) ListChildren(ctx context.Context, req types.ListChildrenRequest) (types.ListResult, types.PaginationInfo, error)
ListChildren lists children of a service with pagination support
func (*ServiceManager) ListDrives ¶
func (m *ServiceManager) ListDrives(ctx context.Context, serviceID string) ([]types.DriveInfo, error)
ListDrives lists available drives/volumes on the system This is primarily useful for Windows (C:\, D:\, etc.) but also works on Unix systems serviceID can be "local" (virtual service) or a specific local service ID
func (*ServiceManager) ListSources ¶
ListSources returns a list of all available sources
func (*ServiceManager) LoadServices ¶
func (m *ServiceManager) LoadServices(localServices []types.LocalServiceConfig, spectraServices []types.SpectraServiceConfig) error
LoadServices loads services from the provided service definitions
func (*ServiceManager) RegisterSpectraSession ¶
func (m *ServiceManager) RegisterSpectraSession(configPath string, connectionID string) (string, error)
RegisterSpectraSession creates a new Spectra session and registers it with the ServiceManager. The ServiceManager owns the session lifecycle - the API should not hold a reference to it. Returns a sessionID that can be used to acquire adapters from this session. If connectionID is empty, a unique ID will be generated.
func (*ServiceManager) ReleaseConnection ¶
func (m *ServiceManager) ReleaseConnection(connectionID string)
ReleaseConnection releases a connection reference
type SpectraFS ¶
type SpectraFS struct {
// contains filtered or unexported fields
}
SpectraFS implements FSAdapter for Spectra filesystem simulator.
func NewSpectraFS ¶
func NewSpectraFS(spectraFS *sdk.SpectraFS, rootID string, world string, isEphemeral bool) (*SpectraFS, error)
newSpectraFS creates a SpectraFS adapter from a session-owned SDK instance. The adapter does not own the lifecycle of the SDK instance - the session does. This function does NOT validate the root node - it assumes the session is valid.
func (*SpectraFS) CreateFile ¶
func (s *SpectraFS) CreateFile(ctx context.Context, parentID, name string, size int64, metadata map[string]string) (types.File, error)
CreateFile creates a file entry in Spectra with metadata only. The actual file data will be uploaded when OpenWrite().Close() is called. This avoids uploading empty data, which the Spectra SDK now rejects.
func (*SpectraFS) CreateFolder ¶
CreateFolder creates a new folder under the specified parent node.
func (*SpectraFS) GetSDKInstance ¶
GetSDKInstance returns the underlying Spectra SDK instance. This is used to check if multiple adapters share the same instance.
func (*SpectraFS) ListChildren ¶
func (s *SpectraFS) ListChildren(identifier string, depth *int, parentPath string) (types.ListResult, error)
ListChildren lists immediate children of the given node identifier (Spectra node ID). It currently retrieves the full child set in one call to the Spectra SDK. For consistency with other services and future-proofing against backend pagination, callers that want to process children in fixed-size pages should wrap this with NewListPager(result, pageSize). For ephemeral mode, depth and parentPath must be provided by the caller (no persisted node to read from). For persistent mode, depth and parentPath are optional.
func (*SpectraFS) NewChildrenPager ¶
func (s *SpectraFS) NewChildrenPager(identifier string, pageSize int, depth *int, parentPath string) (*types.ListPager, error)
NewChildrenPager is a convenience wrapper that returns a ListPager over the children of a Spectra node. It mirrors the SDK-style pagination model used by many cloud services while keeping the FSAdapter interface simple.
func (*SpectraFS) NormalizePath ¶
NormalizePath normalizes a Spectra node ID or path string.
func (*SpectraFS) OpenRead ¶
OpenRead retrieves file data from Spectra and returns a readable stream. The worker owns the copy loop - this just provides the stream.
func (*SpectraFS) OpenWrite ¶
OpenWrite returns a WriteCloser that buffers writes internally. Since Spectra SDK requires all data upfront, this buffers in memory or to a temp file. On Close(), it creates the file in Spectra with the actual data. The fileID must be a "pending:" ID returned from CreateFile().
type SpectraSession ¶
type SpectraSession struct {
// contains filtered or unexported fields
}
SpectraSession manages a single Spectra SDK instance and provides adapters for it. This is the ONLY place where sdk.New() is allowed to be called.
func NewSpectraSession ¶
func NewSpectraSession(configPath string) (*SpectraSession, error)
NewSpectraSession creates a new Spectra session by calling sdk.New(). This is the ONLY place in the codebase where sdk.New() should be called.
func (*SpectraSession) Close ¶
func (s *SpectraSession) Close() error
Close closes the Spectra SDK instance. Safe to call multiple times.
func (*SpectraSession) CreateAdapter ¶
func (s *SpectraSession) CreateAdapter(rootID, world string) (*SpectraFS, error)
CreateAdapter creates a SpectraFS adapter for the given rootID and world. The adapter does not own the lifecycle of the SDK instance. Returns an error immediately if the session is closed (fail fast).
func (*SpectraSession) GetConfigPath ¶
func (s *SpectraSession) GetConfigPath() string
GetConfigPath returns the config path used to create this session.
func (*SpectraSession) IsClosed ¶
func (s *SpectraSession) IsClosed() bool
IsClosed returns whether the session is closed.
func (*SpectraSession) IsEphemeral ¶
func (s *SpectraSession) IsEphemeral() bool
IsEphemeral returns whether this session is in ephemeral mode.