light refacto

This commit is contained in:
ppom 2023-05-01 18:21:31 +02:00
parent 3499cfd6c8
commit 4c86f37b70
2 changed files with 11 additions and 9 deletions

View File

@ -180,9 +180,6 @@ var wgActions sync.WaitGroup
var db *gob.Encoder var db *gob.Encoder
func Main() { func Main() {
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
confFilename := flag.String("c", "", "configuration file. see an example at https://framagit.org/ppom/reaction/-/blob/main/reaction.yml") confFilename := flag.String("c", "", "configuration file. see an example at https://framagit.org/ppom/reaction/-/blob/main/reaction.yml")
flag.Parse() flag.Parse()
@ -191,8 +188,13 @@ func Main() {
os.Exit(2) os.Exit(2)
} }
conf, localdb := parseConf(*confFilename) conf := parseConf(*confFilename)
db = localdb db = conf.updateFromDB()
// Ready to start
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
stopStreams = make(chan bool) stopStreams = make(chan bool)
stopActions = make(chan bool) stopActions = make(chan bool)

View File

@ -19,6 +19,9 @@ type Conf struct {
Streams map[string]*Stream `yaml:"streams"` Streams map[string]*Stream `yaml:"streams"`
} }
// Stream, Filter & Action structures must never be copied.
// They're always referenced through pointers
type Stream struct { type Stream struct {
name string `yaml:"-"` name string `yaml:"-"`
@ -248,7 +251,6 @@ func (c *Conf) updateFromDB() *gob.Encoder {
func parseConf(filename string) (*Conf, *gob.Encoder) { func parseConf(filename string) (*Conf, *gob.Encoder) {
data, err := os.ReadFile(filename) data, err := os.ReadFile(filename)
if err != nil { if err != nil {
log.Fatalln("FATAL Failed to read configuration file:", err) log.Fatalln("FATAL Failed to read configuration file:", err)
} }
@ -260,7 +262,5 @@ func parseConf(filename string) (*Conf, *gob.Encoder) {
} }
conf.setup() conf.setup()
enc := conf.updateFromDB() return &conf
return &conf, enc
} }