service

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 25, 2025 License: MIT Imports: 15 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func ReadDomainsFile

func ReadDomainsFile(filename string) ([]model.DomainEntry, 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.DomainEntry) 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

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, registry *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) 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 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() ([]*model.DomainEntry, error)

ListDomains returns all 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) Watch

func (fw *FileWatcher) Watch()

func (*FileWatcher) WithLogger

func (fw *FileWatcher) WithLogger(l *zap.Logger) *FileWatcher

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL