Documentation
¶
Overview ¶
Package service provides core business logic for the dehydrated-api-go application. It includes domain management, file operations, and plugin integration services.
Package service provides core business logic for the dehydrated-api-go application. It includes domain management, file operations, and plugin integration services.
Index ¶
- func ReadDomainsFile(filename string) (model.DomainEntries, error)
- func WriteDomainsFile(filename string, entries model.DomainEntries) error
- type DomainService
- func (s *DomainService) Close() error
- func (s *DomainService) CreateDomain(req *model.CreateDomainRequest) (*model.DomainEntry, error)
- func (s *DomainService) DeleteDomain(domain string, req model.DeleteDomainRequest) error
- func (s *DomainService) GetDomain(domain, alias string) (*model.DomainEntry, error)
- func (s *DomainService) ListDomains(page, perPage int, sortOrder, search string) ([]*model.DomainEntry, *model.PaginationInfo, error)
- func (s *DomainService) Reload() error
- func (s *DomainService) UpdateDomain(domain string, req model.UpdateDomainRequest) (*model.DomainEntry, error)
- func (s *DomainService) WithFileWatcher() *DomainService
- func (s *DomainService) WithLogger(l *zap.Logger) *DomainService
- type FileWatcher
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ReadDomainsFile ¶
func ReadDomainsFile(filename string) (model.DomainEntries, error)
ReadDomainsFile reads a domains.txt file and returns a slice of DomainEntry. It parses the file format which supports: - Domain names with optional alternative names - Aliases using the '>' syntax - Comments using '#' prefix or inline - Disabled entries (prefixed with '#')
func WriteDomainsFile ¶
func WriteDomainsFile(filename string, entries model.DomainEntries) error
WriteDomainsFile writes a slice of DomainEntry to a domains.txt file. It formats each entry according to the dehydrated domains.txt format: - Disabled entries are prefixed with '#' - Alternative names are space-separated - Aliases are added with ' > ' separator - Comments are added with ' # ' separator - Entries are automatically sorted alphabetically before writing using the DomainEntries.Sort() method
Types ¶
type DomainService ¶
type DomainService struct {
DehydratedConfig *dehydrated.Config // Path to the domains.txt file
// contains filtered or unexported fields
}
DomainService handles domain-related business logic and operations. It manages domain entries, integrates with plugins, and provides thread-safe access to domain data.
func NewDomainService ¶
func NewDomainService(cfg *dehydrated.Config, r *registry.Registry) *DomainService
NewDomainService creates a new DomainService instance with the provided configuration. It initializes the dehydrated client, sets up the plugin registry, and optionally enables file watching for automatic updates.
func (*DomainService) Close ¶
func (s *DomainService) Close() error
Close cleans up resources used by the DomainService. It stops the file watcher and closes all plugin connections.
func (*DomainService) CreateDomain ¶
func (s *DomainService) CreateDomain(req *model.CreateDomainRequest) (*model.DomainEntry, error)
CreateDomain adds a new domain entry to the domains file. It validates the entry, checks for duplicates, and updates both the cache and file.
func (*DomainService) DeleteDomain ¶
func (s *DomainService) DeleteDomain(domain string, req model.DeleteDomainRequest) error
DeleteDomain removes a domain entry from both the cache and the domains file. It returns an error if the domain is not found.
func (*DomainService) GetDomain ¶
func (s *DomainService) GetDomain(domain, alias string) (*model.DomainEntry, error)
GetDomain retrieves a domain entry by its domain name. It returns a copy of the entry with metadata enriched from plugins.
func (*DomainService) ListDomains ¶
func (s *DomainService) ListDomains(page, perPage int, sortOrder, search string) ([]*model.DomainEntry, *model.PaginationInfo, error)
ListDomains returns paginated domain entries with their metadata enriched from plugins. It returns a copy of the cached entries to prevent modification of the cache.
func (*DomainService) Reload ¶
func (s *DomainService) Reload() error
Reload reloads the domain entries from the file into the cache. This method is called during initialization and when file changes are detected.
func (*DomainService) UpdateDomain ¶
func (s *DomainService) UpdateDomain(domain string, req model.UpdateDomainRequest) (*model.DomainEntry, error)
UpdateDomain updates an existing domain entry with new information. It validates the updated entry and writes the changes to both cache and file.
func (*DomainService) WithFileWatcher ¶
func (s *DomainService) WithFileWatcher() *DomainService
func (*DomainService) WithLogger ¶
func (s *DomainService) WithLogger(l *zap.Logger) *DomainService
type FileWatcher ¶
type FileWatcher struct {
// contains filtered or unexported fields
}
FileWatcher watches for changes to a file and triggers a callback when changes are detected. It implements debouncing to prevent multiple rapid callbacks for the same file change.
func NewFileWatcher ¶
func NewFileWatcher(filePath string, onChange func() error) (*FileWatcher, error)
NewFileWatcher creates a new FileWatcher instance for the specified file. It sets up the filesystem watcher and starts a goroutine to monitor for changes. The onChange callback will be called when the file is modified, created, or removed.
func (*FileWatcher) Close ¶
func (fw *FileWatcher) Close() error
Close stops the file watcher and releases associated resources.
func (*FileWatcher) Disable ¶ added in v0.2.0
func (fw *FileWatcher) Disable()
func (*FileWatcher) Enable ¶ added in v0.2.0
func (fw *FileWatcher) Enable()
func (*FileWatcher) Watch ¶
func (fw *FileWatcher) Watch()
func (*FileWatcher) WithLogger ¶
func (fw *FileWatcher) WithLogger(l *zap.Logger) *FileWatcher