server

package
v1.5.4 Latest Latest
Warning

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

Go to latest
Published: May 8, 2026 License: MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultGroup = "default"

DefaultGroup is the name used when no explicit group is specified.

Variables

View Source
var ErrBinaryFile = errors.New("binary file is not supported")

ErrBinaryFile is returned when a file is detected as binary.

View Source
var ErrFileNotFound = errors.New("file not found")

ErrFileNotFound is returned when a file is not found in the specified group.

Functions

func FileID added in v0.16.0

func FileID(absPath string) string

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 NewHandler(state *State) http.Handler

func ResolveGroupName added in v0.11.1

func ResolveGroupName(name string) (string, error)

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 FileEntry

type FileEntry struct {
	Name     string `json:"name"`
	ID       string `json:"id"`
	Path     string `json:"path"`
	Title    string `json:"title,omitempty"`
	Uploaded bool   `json:"uploaded,omitempty"`
	// contains filtered or unexported fields
}

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 Group

type Group struct {
	Name  string       `json:"name"`
	Files []*FileEntry `json:"files"`
}

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 NewState

func NewState(ctx context.Context) *State

func (*State) AddFile

func (s *State) AddFile(absPath, groupName string) (*FileEntry, error)

func (*State) AddPattern added in v0.13.0

func (s *State) AddPattern(absPattern, groupName string) ([]*FileEntry, error)

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 (s *State) AddUploadedFile(name, content, groupName string) *FileEntry

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

func (s *State) ExportState() (string, error)

ExportState writes the current groups, file paths, and patterns to a temporary file and returns the path.

func (*State) FindFile

func (s *State) FindFile(id, groupName string) *FileEntry

func (*State) Groups

func (s *State) Groups() []Group

func (*State) MoveFile added in v0.10.0

func (s *State) MoveFile(id, sourceGroupName, targetGroup string) error

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

func (s *State) PatternsForGroup(groupName string) []string

PatternsForGroup returns the pattern strings for a specific group.

func (*State) RemoveFile added in v0.9.0

func (s *State) RemoveFile(id, groupName string) bool

func (*State) RemoveFilesByPath added in v1.5.1

func (s *State) RemoveFilesByPath(absPath string) bool

RemoveFilesByPath removes every file entry whose path matches absPath across all groups, cleans up the watcher, and drops any groups left empty without patterns. Returns true if at least one entry was removed.

func (*State) RemovePattern added in v0.13.1

func (s *State) RemovePattern(absPattern, groupName string) bool

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 (s *State) ReorderFiles(groupName string, fileIDs []string) bool

func (*State) RestartCh added in v0.9.0

func (s *State) RestartCh() <-chan string

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) Subscribe

func (s *State) Subscribe() chan sseEvent

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.

Jump to

Keyboard shortcuts

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