From 6c8141e43bd560594b936cd059244ed35302519b Mon Sep 17 00:00:00 2001 From: nadoo <287492+nadoo@users.noreply.github.com> Date: Wed, 18 Sep 2019 17:10:33 +0800 Subject: [PATCH] strategy: return fwdr's addr when only 1 fwdr left --- conf.go | 2 +- strategy/strategy.go | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/conf.go b/conf.go index c95ae94..020fc2f 100644 --- a/conf.go +++ b/conf.go @@ -103,7 +103,7 @@ func confInit() { func usage() { app := os.Args[0] fmt.Fprintf(os.Stderr, "\n") - fmt.Fprintf(os.Stderr, "%s v%s usage:\n", app, version) + fmt.Fprintf(os.Stderr, "%s %s usage:\n", app, version) flag.PrintDefaults() fmt.Fprintf(os.Stderr, "\n") diff --git a/strategy/strategy.go b/strategy/strategy.go index f3384fe..0ccd9df 100644 --- a/strategy/strategy.go +++ b/strategy/strategy.go @@ -15,11 +15,6 @@ import ( "github.com/nadoo/glider/proxy" ) -// Checker is an interface of forwarder checker. -type Checker interface { - Check() -} - // Config is strategy config struct. type Config struct { Strategy string @@ -107,7 +102,13 @@ func newDialer(fwdrs []*Forwarder, c *Config) *Dialer { } // Addr returns forwarder's address. -func (d *Dialer) Addr() string { return "STRATEGY" } +func (d *Dialer) Addr() string { + if d.fwdrs.Len() == 1 { + return d.fwdrs[0].Addr() + } + + return "STRATEGY" +} // Dial connects to the address addr on the network net. func (d *Dialer) Dial(network, addr string) (net.Conn, string, error) {