Esempio n. 1
0
func (p *Proxy) ReloadRules(filename string) error {
	rules, err := rule.ParseJSON(filename)
	if err != nil {
		return err
	}
	p.Rules = &rules
	return nil
}
Esempio n. 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")
	flag.Parse()
	rules, err := rule.ParseJSON(*ruleFile)
	if err != nil {
		log.Fatal("Cannot parse rules: ", err)
		return
	}
	log.Println(len(rules), "rules loaded from", *ruleFile)
	p := proxy.Listen(*listen, *target, &rules)
	api.Listen(*apiAddr, *ruleFile, p)
}