Help us shape the future of Go! Take the 2026 Go Developer Survey

rules

package
v0.8.2 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2026 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatRule added in v0.5.2

func FormatRule(r models.Rule) string

FormatRule renders a Rule back into the human-readable rule syntax shown in the CLI, e.g. "type=Video && size>1GB -> Videos/Large".

Round trip: for a rule whose Conditions are populated, ParseRule(FormatRule(r), 0) yields the same Conditions and Destination, except for two limitations inherited from ParseRule. It reads a left-hand side free of '=', '>', '<' and '&&' as a bare glob, so a rule whose only clause uses a word operator does not survive. And mapField has no 'mod_time' case, so a rule using models.FieldModTime renders to text ParseRule rejects outright. Rules built from the preset helper fields (Type, Extensions, MinSize, MaxSize) fall back to rendering those helpers as clauses, which is display-only and deliberately lossy — the rendered string parses, but not back into the helpers.

func ParseRule

func ParseRule(ruleStr string, priority int) (models.Rule, error)

ParseRule parses CLI rule string e.g.: "type=video && size>1GB -> Videos/Large" "name=~'^IMG_' -> Camera" "*.mp4 -> Videos" "size>500MB -> Huge"

func ParseSize

func ParseSize(s string) (int64, error)

ParseSize parses human readable byte sizes: "500KB", "1GB", "2.5MB", "1024"

func ValidateRule added in v0.7.0

func ValidateRule(r models.Rule) []error

ValidateRule reports every problem that makes a rule evaluate incorrectly: unparseable helper sizes, unknown fields, operators a field does not support, unparseable size values and regexes that do not compile. A nil result means the rule is safe to evaluate.

func ValidateRules added in v0.7.0

func ValidateRules(rs []models.Rule) []error

ValidateRules aggregates the problems of every rule, preserving rule order.

Types

type Engine

type Engine struct {
	// contains filtered or unexported fields
}

Engine evaluates rules against files

func NewEngine

func NewEngine(rules []models.Rule) *Engine

NewEngine creates a new Rule Engine

func (*Engine) Evaluate

func (e *Engine) Evaluate(file models.File) (*models.Rule, string, bool)

Evaluate finds the highest priority matching rule for a file

Jump to

Keyboard shortcuts

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