reaction/app/types.go
ppom a119e0814b one goroutine handles all actions
pending actions are now data, they're not goroutines anymore ❤️

warn: cli currently doesn't work, but it's already a huge commit
2023-09-22 18:12:11 +02:00

105 lines
1.9 KiB
Go

package app
import (
"encoding/gob"
"os"
"regexp"
"time"
)
type Conf struct {
Patterns map[string]*Pattern `yaml:"patterns"`
Streams map[string]*Stream `yaml:"streams"`
}
type Pattern struct {
Regex string `yaml:"regex"`
Ignore []string `yaml:"ignore"`
name string `yaml:"-"`
nameWithBraces string `yaml:"-"`
}
// Stream, Filter & Action structures must never be copied.
// They're always referenced through pointers
type Stream struct {
name string `yaml:"-"`
Cmd []string `yaml:"cmd"`
Filters map[string]*Filter `yaml:"filters"`
}
type Filter struct {
stream *Stream `yaml:"-"`
name string `yaml:"-"`
Regex []string `yaml:"regex"`
compiledRegex []regexp.Regexp `yaml:"-"`
pattern *Pattern `yaml:"-"`
Retry int `yaml:"retry"`
RetryPeriod string `yaml:"retry-period"`
retryDuration time.Duration `yaml:"-"`
Actions map[string]*Action `yaml:"actions"`
longuestActionDuration *time.Duration
}
type Action struct {
filter *Filter `yaml:"-"`
name string `yaml:"-"`
Cmd []string `yaml:"cmd"`
After string `yaml:"after"`
afterDuration time.Duration `yaml:"-"`
OnExit bool `yaml:"onexit"`
}
type LogEntry struct {
T time.Time
Pattern string
Stream, Filter string
Exec bool
}
type ReadDB struct {
file *os.File
dec *gob.Decoder
}
type WriteDB struct {
file *os.File
enc *gob.Encoder
}
type PatternTimes map[string][]time.Time
type MatchesMap map[*Filter]PatternTimes
type ActionsMap map[*Action]PatternTimes
// Helper structs made to carry information across channels
type SF struct{ s, f string }
type PSF struct{ p, s, f string }
type PF struct {
p string
f *Filter
}
type PFT struct {
p string
f *Filter
t time.Time
}
type PA struct {
p string
a *Action
}
type PAT struct {
p string
a *Action
t time.Time
}