-
Notifications
You must be signed in to change notification settings - Fork 27
/
filtron.go
37 lines (31 loc) · 1 KB
/
filtron.go
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
package main
import (
"flag"
"fmt"
"log"
"github.com/asciimoo/filtron/api"
"github.com/asciimoo/filtron/proxy"
"github.com/asciimoo/filtron/rule"
)
const VERSION string = "0.2.0"
func main() {
target := flag.String("target", "127.0.0.1:8888", "Target address for reverse proxy")
listen := flag.String("listen", "127.0.0.1:4004", "Proxy listen address")
apiAddr := flag.String("api", "127.0.0.1:4005", "API listen address")
ruleFile := flag.String("rules", "rules.json", "JSON rule list")
readBufferSize := flag.Int("read-buffer-size", 16*1024, "Read buffer size")
printVersionInfo := flag.Bool("version", false, "Version information")
flag.Parse()
if *printVersionInfo {
fmt.Printf("Filtron v%s\n", VERSION)
return
}
rules, err := rule.ParseJSONFile(*ruleFile)
if err != nil {
log.Fatal("Cannot parse rules: ", err)
return
}
log.Println(rule.RulesLength(rules), "rules loaded from", *ruleFile)
p := proxy.Listen(*listen, *target, *readBufferSize, &rules)
api.Listen(*apiAddr, *ruleFile, p)
}