mirror of
				https://github.com/nadoo/glider.git
				synced 2025-11-04 07:42:38 +08:00 
			
		
		
		
	general: use string slice instead of custom arrFlags type.
This commit is contained in:
		
							parent
							
								
									085e6ba040
								
							
						
					
					
						commit
						ed788fd1c7
					
				
							
								
								
									
										31
									
								
								main.go
									
									
									
									
									
								
							
							
						
						
									
										31
									
								
								main.go
									
									
									
									
									
								
							@ -19,9 +19,9 @@ var conf struct {
 | 
				
			|||||||
	Strategy      string
 | 
						Strategy      string
 | 
				
			||||||
	CheckWebSite  string
 | 
						CheckWebSite  string
 | 
				
			||||||
	CheckDuration int
 | 
						CheckDuration int
 | 
				
			||||||
	Listen        arrFlags
 | 
						Listen        []string
 | 
				
			||||||
	Forward       arrFlags
 | 
						Forward       []string
 | 
				
			||||||
	RuleFile      arrFlags
 | 
						RuleFile      []string
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
var flag = conflag.New()
 | 
					var flag = conflag.New()
 | 
				
			||||||
@ -108,34 +108,15 @@ func usage() {
 | 
				
			|||||||
	fmt.Fprintf(os.Stderr, "\n")
 | 
						fmt.Fprintf(os.Stderr, "\n")
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type arrFlags []string
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// implement flag.Value interface
 | 
					 | 
				
			||||||
func (i *arrFlags) String() string {
 | 
					 | 
				
			||||||
	return ""
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// implement flag.Value interface
 | 
					 | 
				
			||||||
func (i *arrFlags) Set(value string) error {
 | 
					 | 
				
			||||||
	// for _, v := range *i {
 | 
					 | 
				
			||||||
	// 	if v == value {
 | 
					 | 
				
			||||||
	// 		return nil
 | 
					 | 
				
			||||||
	// 	}
 | 
					 | 
				
			||||||
	// }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	*i = append(*i, value)
 | 
					 | 
				
			||||||
	return nil
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func main() {
 | 
					func main() {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	flag.BoolVar(&conf.Verbose, "verbose", false, "verbose mode")
 | 
						flag.BoolVar(&conf.Verbose, "verbose", false, "verbose mode")
 | 
				
			||||||
	flag.StringVar(&conf.Strategy, "strategy", "rr", "forward strategy, default: rr")
 | 
						flag.StringVar(&conf.Strategy, "strategy", "rr", "forward strategy, default: rr")
 | 
				
			||||||
	flag.StringVar(&conf.CheckWebSite, "checkwebsite", "www.apple.com", "proxy check HTTP(NOT HTTPS) website address, format: HOST[:PORT], default port: 80")
 | 
						flag.StringVar(&conf.CheckWebSite, "checkwebsite", "www.apple.com", "proxy check HTTP(NOT HTTPS) website address, format: HOST[:PORT], default port: 80")
 | 
				
			||||||
	flag.IntVar(&conf.CheckDuration, "checkduration", 30, "proxy check duration(seconds)")
 | 
						flag.IntVar(&conf.CheckDuration, "checkduration", 30, "proxy check duration(seconds)")
 | 
				
			||||||
	flag.Var(&conf.Listen, "listen", "listen url, format: SCHEMA://[USER|METHOD:PASSWORD@][HOST]:PORT")
 | 
						flag.StringSliceVar(&conf.Listen, "listen", nil, "listen url, format: SCHEMA://[USER|METHOD:PASSWORD@][HOST]:PORT")
 | 
				
			||||||
	flag.Var(&conf.Forward, "forward", "forward url, format: SCHEMA://[USER|METHOD:PASSWORD@][HOST]:PORT[,SCHEMA://[USER|METHOD:PASSWORD@][HOST]:PORT]")
 | 
						flag.StringSliceVar(&conf.Forward, "forward", nil, "forward url, format: SCHEMA://[USER|METHOD:PASSWORD@][HOST]:PORT[,SCHEMA://[USER|METHOD:PASSWORD@][HOST]:PORT]")
 | 
				
			||||||
	flag.Var(&conf.RuleFile, "rulefile", "rule file path")
 | 
						flag.StringSliceVar(&conf.RuleFile, "rulefile", nil, "rule file path")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	flag.Usage = usage
 | 
						flag.Usage = usage
 | 
				
			||||||
	err := flag.Parse()
 | 
						err := flag.Parse()
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										16
									
								
								rule.go
									
									
									
									
									
								
							
							
						
						
									
										16
									
								
								rule.go
									
									
									
									
									
								
							@ -11,14 +11,14 @@ import (
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
// ruleForwarder, every ruleForwarder points to a rule file
 | 
					// ruleForwarder, every ruleForwarder points to a rule file
 | 
				
			||||||
type ruleForwarder struct {
 | 
					type ruleForwarder struct {
 | 
				
			||||||
	Forward       arrFlags
 | 
						Forward       []string
 | 
				
			||||||
	Strategy      string
 | 
						Strategy      string
 | 
				
			||||||
	CheckWebSite  string
 | 
						CheckWebSite  string
 | 
				
			||||||
	CheckDuration int
 | 
						CheckDuration int
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	Domain arrFlags
 | 
						Domain []string
 | 
				
			||||||
	IP     arrFlags
 | 
						IP     []string
 | 
				
			||||||
	CIDR   arrFlags
 | 
						CIDR   []string
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	name string
 | 
						name string
 | 
				
			||||||
	Proxy
 | 
						Proxy
 | 
				
			||||||
@ -29,14 +29,14 @@ func newRuleProxyFromFile(ruleFile string) (*ruleForwarder, error) {
 | 
				
			|||||||
	p := &ruleForwarder{name: ruleFile}
 | 
						p := &ruleForwarder{name: ruleFile}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	f := conflag.NewFromFile("rule", ruleFile)
 | 
						f := conflag.NewFromFile("rule", ruleFile)
 | 
				
			||||||
	f.Var(&p.Forward, "forward", "forward url, format: SCHEMA://[USER|METHOD:PASSWORD@][HOST]:PORT[,SCHEMA://[USER|METHOD:PASSWORD@][HOST]:PORT]")
 | 
						f.StringSliceVar(&p.Forward, "forward", nil, "forward url, format: SCHEMA://[USER|METHOD:PASSWORD@][HOST]:PORT[,SCHEMA://[USER|METHOD:PASSWORD@][HOST]:PORT]")
 | 
				
			||||||
	f.StringVar(&p.Strategy, "strategy", "rr", "forward strategy, default: rr")
 | 
						f.StringVar(&p.Strategy, "strategy", "rr", "forward strategy, default: rr")
 | 
				
			||||||
	f.StringVar(&p.CheckWebSite, "checkwebsite", "www.apple.com", "proxy check HTTP(NOT HTTPS) website address, format: HOST[:PORT], default port: 80")
 | 
						f.StringVar(&p.CheckWebSite, "checkwebsite", "www.apple.com", "proxy check HTTP(NOT HTTPS) website address, format: HOST[:PORT], default port: 80")
 | 
				
			||||||
	f.IntVar(&p.CheckDuration, "checkduration", 30, "proxy check duration(seconds)")
 | 
						f.IntVar(&p.CheckDuration, "checkduration", 30, "proxy check duration(seconds)")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	f.Var(&p.Domain, "domain", "domain")
 | 
						f.StringSliceVar(&p.Domain, "domain", nil, "domain")
 | 
				
			||||||
	f.Var(&p.IP, "ip", "ip")
 | 
						f.StringSliceVar(&p.IP, "ip", nil, "ip")
 | 
				
			||||||
	f.Var(&p.CIDR, "cidr", "cidr")
 | 
						f.StringSliceVar(&p.CIDR, "cidr", nil, "cidr")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	err := f.Parse()
 | 
						err := f.Parse()
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user