fileMonitor

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2025 License: MIT Imports: 20 Imported by: 0

README

go-fileMonitor

Note if using SMB mount on linux, ensure that cifs-utils or equivalent is installed. Typically installed with: sudo apt install cifs-utils

Documentation

Index

Constants

View Source
const (
	CopierTypeNull = iota
	CopierTypeLocal
	CopierTypeFTP
)

Variables

This section is empty.

Functions

func SmbMount added in v0.0.3

func SmbMount(username, password, server, shareName string) error

func SmbRemove added in v0.0.3

func SmbRemove(server, shareName string) error

Types

type Copier

type Copier interface {
	Copy(dir, monitorDir string) error
	GetType() CopierType
	MarshalJSON() ([]byte, error) // Must inject type into object
}

type CopierAlias added in v0.1.3

type CopierAlias struct {
	Type    CopierType
	Details json.RawMessage
}

func (*CopierAlias) GetCopier added in v0.1.3

func (c *CopierAlias) GetCopier() (Copier, error)

func (*CopierAlias) UnmarshalJSON added in v0.1.3

func (c *CopierAlias) UnmarshalJSON(data []byte) error

type CopierFtp added in v0.1.3

type CopierFtp struct {
	Server      string
	Username    string
	Password    string // Does not store the password directly and only stores encrypted using the encryptionFunc
	Destination string

	EncryptionFunc func(string) (string, error) `json:"-"` // Not stored in JSON
	DecryptionFunc func(string) (string, error) `json:"-"` // Not stored in JSON
}

func (*CopierFtp) Copy added in v0.1.3

func (c *CopierFtp) Copy(inFilePath, monitorDir string) error

func (*CopierFtp) GetType added in v0.1.3

func (c *CopierFtp) GetType() CopierType

func (*CopierFtp) MarshalJSON added in v0.1.3

func (f *CopierFtp) MarshalJSON() ([]byte, error)

type CopierLocal

type CopierLocal struct {
	Destination string
}

func (*CopierLocal) Copy

func (c *CopierLocal) Copy(filePath, monitorDir string) error

func (*CopierLocal) GetType added in v0.1.3

func (c *CopierLocal) GetType() CopierType

func (*CopierLocal) MarshalJSON added in v0.1.3

func (c *CopierLocal) MarshalJSON() ([]byte, error)

type CopierType

type CopierType int

type Dir

type Dir struct {
	Name             string
	MonitorFolder    string
	MonitorFrequency time.Duration
	KeepEmptyDirs    bool
	Active           bool
	MatchGroups      []MatchGroup

	Processor  *Processor
	Publishers []Publisher `json:"-"`
	Copiers    []Copier

	// Copier to use if an error occurs after a match as original file will be delete
	ErrorCopiers []Copier

	Stats Stats
	// contains filtered or unexported fields
}

func (*Dir) Monitor

func (d *Dir) Monitor() error

func (*Dir) UnmarshalJSON added in v0.1.3

func (d *Dir) UnmarshalJSON(input []byte) error

type FileMonitor

type FileMonitor struct {
	Dirs       map[string]*Dir
	MaxJobs    uint // maximum number of jobs that can be buffered without waiting
	NumWorkers uint // number of workers processing files
	// contains filtered or unexported fields
}

func NewFileMonitor added in v0.0.3

func NewFileMonitor(parentCtx context.Context, logger zerolog.Logger, configPath string) (*FileMonitor, error)

func (*FileMonitor) AddAllDirPublisher added in v0.0.3

func (f *FileMonitor) AddAllDirPublisher(publisher Publisher)

func (*FileMonitor) AddDir

func (f *FileMonitor) AddDir(dir *Dir) error

func (*FileMonitor) Connected

func (f *FileMonitor) Connected() bool

func (*FileMonitor) GetDirs

func (f *FileMonitor) GetDirs() []string

func (*FileMonitor) GetStats

func (f *FileMonitor) GetStats() *Stats

func (*FileMonitor) NewDir

func (f *FileMonitor) NewDir(name, monitorFolder, publishLocation string, monitorFreq time.Duration, processor *Processor, overwriteExistingDir bool, matchGroups []MatchGroup) (*Dir, error)

Creates a new dir

Likely caller will want to add Publisher, Copiers, and/or ErrorCopiers

func (*FileMonitor) RemoveDir

func (f *FileMonitor) RemoveDir(dir *Dir) error

func (*FileMonitor) Start

func (f *FileMonitor) Start() error

func (*FileMonitor) Update

func (f *FileMonitor) Update() error

type MatchGroup

type MatchGroup struct {
	Expression string
	Exclude    bool // If true value must not exist. If false value must exist
	// contains filtered or unexported fields
}

Regex matching for file to be processed

Uses dir + file name with the separator guaranteed to be "/"

func (*MatchGroup) Match

func (m *MatchGroup) Match(filePath string) (match bool, err error)

type Processor

type Processor struct {
	Type     ProcessorType
	Executor ProcessorExecutor
}

func (*Processor) UnmarshalJSON

func (p *Processor) UnmarshalJSON(data []byte) error

type ProcessorExecutor

type ProcessorExecutor interface {
	Process(filepath string) (result [][]byte, id []string, err error)
}

type ProcessorType

type ProcessorType int
const (
	ProcessorTypeNull ProcessorType = iota
	ProcessorTypeCsv
)

type Publisher

type Publisher interface {
	Publish(dir *Dir, result [][]byte, id []string) error
}

type Stats

type Stats struct {
	TotalFiles atomic.Uint64
	TotalBytes atomic.Uint64
}

Stats stored with a connection

func (*Stats) Add

func (s *Stats) Add(other *Stats)

Adds the stats from the other stats

func (*Stats) Inc

func (s *Stats) Inc(totalBytes uint64)

Increments the stats

func (*Stats) Reset

func (s *Stats) Reset()

Resets the stats

func (*Stats) String

func (s *Stats) String() string

String representation of the stats

func (*Stats) Sub

func (s *Stats) Sub(other *Stats)

Subtracts the stats from the other stats

Jump to

Keyboard shortcuts

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