Last active
April 5, 2017 04:37
-
-
Save gnilchee/88ecc10563954f8ceecc602f2325bc08 to your computer and use it in GitHub Desktop.
fun with command line arguments
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
package main | |
import ( | |
"flag" | |
"fmt" | |
) | |
func main() { | |
var ( | |
secureAddress = flag.Bool("secure", false, "Set https as protocol") | |
hostAddress = flag.String("host", "example.com", "Hostname, include port if non-standard. i.e. example.com:8080") | |
hostPath = flag.String("path", "/", "Path URI.") | |
whatProto string | |
) | |
flag.Parse() | |
if *secureAddress { | |
whatProto = "https" | |
} else { | |
whatProto = "http" | |
} | |
fmt.Println(whatProto + "://" + *hostAddress + *hostPath) | |
} |
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
# ./cmd_args | |
http://example.com:80/ | |
# ./cmd_args --help | |
Usage of ./cmd_args: | |
-host string | |
Hostname, include port if non-standard. i.e. example.com:8080 (default "example.com") | |
-path string | |
Path URI. (default "/") | |
-secure | |
Set https as protocol | |
# ./cmd_args -secure -host google.com -path /robots.txt | |
https://google.com/robots.txt | |
# ./cmd_args -secure -host google.com:8443 -path /robots.txt | |
https://google.com:8443/robots.txt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment