Documentation
¶
Index ¶
- Constants
- Variables
- func FileID(absPath string) string
- func NewHandler(state *State) http.Handler
- func ResolveGroupName(name string) (string, error)
- func WriteRestoreFile(data RestoreData) (string, error)
- type AddPatternResponse
- type FileEntry
- type GlobPattern
- type Group
- type RestoreData
- type State
- func (s *State) AddFile(absPath, groupName string) (*FileEntry, error)
- func (s *State) AddPattern(absPattern, groupName string) ([]*FileEntry, error)
- func (s *State) AddUploadedFile(name, content, groupName string) *FileEntry
- func (s *State) CloseAllSubscribers()
- func (s *State) EnableBackup(ctx context.Context, saveFn func(RestoreData))
- func (s *State) ExportState() (string, error)
- func (s *State) FindFile(id string) *FileEntry
- func (s *State) FindGroupForFile(id string) string
- func (s *State) Groups() []Group
- func (s *State) MoveFile(id string, targetGroup string) error
- func (s *State) Patterns() []*GlobPattern
- func (s *State) PatternsForGroup(groupName string) []string
- func (s *State) RemoveFile(id string) bool
- func (s *State) RemovePattern(absPattern, groupName string) bool
- func (s *State) ReorderFiles(groupName string, fileIDs []string) bool
- func (s *State) RestartCh() <-chan string
- func (s *State) ShutdownCh() <-chan struct{}
- func (s *State) Subscribe() chan sseEvent
- func (s *State) Unsubscribe(ch chan sseEvent)
- type UploadedFileData
Constants ¶
const DefaultGroup = "default"
DefaultGroup is the name used when no explicit group is specified.
Variables ¶
var ErrBinaryFile = errors.New("binary file is not supported")
ErrBinaryFile is returned when a file is detected as binary.
Functions ¶
func FileID ¶ added in v0.16.0
FileID generates a deterministic file ID from an absolute path. The ID is the first 8 characters of the SHA-256 hex digest.
func NewHandler ¶
func ResolveGroupName ¶ added in v0.11.1
ResolveGroupName normalizes the name, falls back to DefaultGroup when empty, and validates non-default names. It is the single entry point that all call sites should use for group-name handling.
func WriteRestoreFile ¶ added in v0.11.0
func WriteRestoreFile(data RestoreData) (string, error)
WriteRestoreFile writes RestoreData to a temporary file and returns the path.
Types ¶
type AddPatternResponse ¶ added in v0.16.0
type AddPatternResponse struct {
Matched int `json:"matched"`
Files []*FileEntry `json:"files,omitempty"`
}
AddPatternResponse is the JSON response for the add-pattern endpoint.
type GlobPattern ¶ added in v0.13.0
type GlobPattern struct {
Pattern string // Absolute glob pattern
PatternSlash string // Pre-converted to forward slashes for doublestar matching
BaseDir string // Base directory extracted via SplitPattern
Group string // Target group for matched files
}
GlobPattern represents a glob pattern being watched for new files.
func (*GlobPattern) IsRecursive ¶ added in v0.13.0
func (gp *GlobPattern) IsRecursive() bool
IsRecursive returns true if the pattern contains ** for recursive matching.
type RestoreData ¶ added in v0.9.0
type RestoreData struct {
Groups map[string][]string `json:"groups"`
Patterns map[string][]string `json:"patterns,omitempty"`
UploadedFiles []UploadedFileData `json:"uploadedFiles,omitempty"`
}
RestoreData represents the state to be persisted across restarts.
type State ¶
type State struct {
// contains filtered or unexported fields
}
func (*State) AddPattern ¶ added in v0.13.0
AddPattern registers a glob pattern for automatic file discovery. It performs an initial expansion to add existing matches and starts watching the base directory for new files.
func (*State) AddUploadedFile ¶ added in v0.16.0
func (*State) CloseAllSubscribers ¶
func (s *State) CloseAllSubscribers()
CloseAllSubscribers closes all SSE subscriber channels so that SSE handlers return and in-flight requests complete before Shutdown.
func (*State) EnableBackup ¶ added in v0.15.0
func (s *State) EnableBackup(ctx context.Context, saveFn func(RestoreData))
EnableBackup starts a background goroutine that periodically saves state via the provided callback when state changes are detected.
func (*State) ExportState ¶ added in v0.9.0
ExportState writes the current groups, file paths, and patterns to a temporary file and returns the path.
func (*State) FindGroupForFile ¶
FindGroupForFile returns the group name for a given file ID.
func (*State) Patterns ¶ added in v0.13.0
func (s *State) Patterns() []*GlobPattern
Patterns returns a copy of all registered glob patterns.
func (*State) PatternsForGroup ¶ added in v0.13.1
PatternsForGroup returns the pattern strings for a specific group.
func (*State) RemoveFile ¶ added in v0.9.0
func (*State) RemovePattern ¶ added in v0.13.1
RemovePattern removes a glob pattern from the watch list. Returns true if the pattern was found and removed.
func (*State) ReorderFiles ¶ added in v0.10.0
func (*State) RestartCh ¶ added in v0.9.0
RestartCh returns a channel that receives the restore file path when a restart is requested.
func (*State) ShutdownCh ¶ added in v0.11.0
func (s *State) ShutdownCh() <-chan struct{}
ShutdownCh returns a channel that signals when a shutdown is requested via API.
func (*State) Unsubscribe ¶
func (s *State) Unsubscribe(ch chan sseEvent)
type UploadedFileData ¶ added in v0.16.0
type UploadedFileData struct {
Name string `json:"name"`
Content string `json:"content"`
Group string `json:"group"`
}
UploadedFileData represents an uploaded file's content for persistence.