-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* proxy related tasks moved to flag.go --> proxyCmd() * default port number added to proxy url * url variable renamed to URL because of name conflict with url pkg
- Loading branch information
Showing
2 changed files
with
38 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"net/url" | ||
) | ||
|
||
const defaultPort = "1080" | ||
|
||
// proxyCmd parses proxy url and adds default port number if not exists. | ||
func proxyCmd(proxy string) (string, error) { | ||
u, err := url.Parse(proxy) | ||
if err != nil { | ||
err = fmt.Errorf("not valid proxy address: %s", err.Error()) | ||
return "", err | ||
} | ||
if u.Port() == "" { | ||
if proxy[len(proxy)-1] != ':' { | ||
proxy += ":" | ||
} | ||
proxy += defaultPort | ||
} | ||
return proxy, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters