~nvkv/amitm

ref: 8e97a3adb5416f4daa7c5fb1be97786ceeece6fd amitm/cmd/amitm/main.go -rw-r--r-- 687 bytes
8e97a3adSemyon Novikov Even more useful now 3 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package main

import (
	"log"

	"9fans.net/go/acme"
	"git.sr.ht/~nvkv/amitm/internal/amitm/v1"
	"git.sr.ht/~nvkv/amitm/internal/config/v1"
)

func main() {
	l, err := acme.Log()
	if err != nil {
		log.Fatal(err)
	}

	config, err := config.ReadConfigFile("./examples/amitm.toml")
	if err != nil {
		log.Fatal(err)
	}

	for {
		event, err := l.Read()
		if err != nil {
			log.Fatal(err)
		}

		rules, ok := config.RulesForAction(event.Op)
		matched := amitm.Match(rules, event)
		if ok {
			for _, rule := range matched {
				out, err := amitm.Apply(rule, event)
				log.Printf("%s:\n%s", rule.Name, string(out))
				if err != nil {
					log.Printf("error: %s\n", err)
				}
			}
		}
	}
}