Documentation
¶
Overview ¶
Package adapters provides bridge implementations that connect internal application components with the external API package interfaces, enabling dependency injection and clean separation of concerns.
This package implements the Adapter pattern to translate between the internal configuration, logging, and caching systems and the standardized interfaces expected by the API client. This design allows for:
- Clean dependency injection throughout the application
- Easy testing with mock implementations
- Loose coupling between internal and external components
- Consistent interface contracts across the codebase
The adapters handle the translation of internal types to interface implementations while maintaining type safety and proper error handling.
Available Adapters:
- ConfigAdapter: Wraps internal.Config to implement interfaces.Config
- LoggerAdapter: Wraps internal.Logger to implement interfaces.Logger
- CacheAdapter: Wraps internal.Cache to implement interfaces.Cache
Example usage:
// Create internal components config := config.NewConfig() logger := logger.NewInternalLogger(logger.LevelInfo, config.CacheDir) cache := cache.NewFileCache(config.CacheDir, false) // Wrap with adapters for API client configAdapter := adapters.NewConfigAdapter(config) loggerAdapter := adapters.NewLoggerAdapter(logger) cacheAdapter := adapters.NewCacheAdapter(cache) // Use with API client client, err := api.NewClient(configAdapter, api.WithLogger(loggerAdapter), api.WithCache(cacheAdapter))
Thread Safety:
All adapters are designed to be thread-safe and delegate thread safety concerns to their underlying implementations. The adapters themselves add no additional synchronization overhead.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewCacheAdapter ¶
func NewCacheAdapter() interfaces.Cache
NewCacheAdapter creates a new cache adapter.
func NewConfigAdapter ¶
func NewConfigAdapter(cfg *config.Config) interfaces.Config
NewConfigAdapter creates a new config adapter.
func NewLoggerAdapter ¶
func NewLoggerAdapter(cfg *config.Config) interfaces.Logger
NewLoggerAdapter creates a new logger adapter with the given configuration.
NewLoggerAdapter creates a logger adapter using the global logger system. This ensures consistent logging behavior across the application.
Parameters:
- cfg: Configuration containing debug settings and cache directory
Returns a logger adapter that implements the interfaces.Logger interface.
func NewSimpleLoggerAdapter ¶
func NewSimpleLoggerAdapter(debugEnabled bool) interfaces.Logger
NewSimpleLoggerAdapter creates a logger adapter with simple stdout logging.
Types ¶
type CacheAdapter ¶
type CacheAdapter struct {
// contains filtered or unexported fields
}
CacheAdapter adapts our internal cache to the API interface.
func (*CacheAdapter) Clear ¶
func (c *CacheAdapter) Clear() error
func (*CacheAdapter) Delete ¶
func (c *CacheAdapter) Delete(key string) error
type ConfigAdapter ¶
ConfigAdapter adapts our internal config to the API interface.
type LoggerAdapter ¶
type LoggerAdapter struct {
// contains filtered or unexported fields
}
LoggerAdapter adapts our internal logging to the API interface.
func (*LoggerAdapter) Debug ¶
func (l *LoggerAdapter) Debug(format string, args ...interface{})
func (*LoggerAdapter) Error ¶
func (l *LoggerAdapter) Error(format string, args ...interface{})
func (*LoggerAdapter) GetInternalLogger ¶
func (l *LoggerAdapter) GetInternalLogger() *logger.Logger
GetInternalLogger returns the internal logger instance for VNC service compatibility.
func (*LoggerAdapter) Info ¶
func (l *LoggerAdapter) Info(format string, args ...interface{})