diff options
author | aqua <aqua@iserlohn-fortress.net> | 2021-07-28 23:05:49 +0300 |
---|---|---|
committer | aqua <aqua@iserlohn-fortress.net> | 2021-07-28 23:05:49 +0300 |
commit | d5e25d80182d38b49f6e4a78bed653e4bdb9c747 (patch) | |
tree | 4d65849f203523f43f1ba21838161bf56d589344 | |
parent | Initial commit (diff) | |
download | gemcat-d5e25d80182d38b49f6e4a78bed653e4bdb9c747.tar.xz |
Use cmd args to get request url
-rw-r--r-- | main.go | 28 |
1 files changed, 26 insertions, 2 deletions
@@ -2,17 +2,41 @@ package main import ( "crypto/tls" + "flag" + "fmt" "log" + "os" + "strconv" ) -const url = "gemini.circumlunar.space:1965" -const request = "gemini://gemini.circumlunar.space/\r\n" +var port = 1965 + +func usage() { + fmt.Printf("Usage: %s [options] url\n", os.Args[0]) + flag.PrintDefaults() +} func main() { + flag.Usage = usage + + flag.IntVar(&port, "p", port, "server port number") + + flag.Parse() + if flag.NArg() != 1 { + fmt.Printf("Got %d arguments, expected 1\n", flag.NArg()) + flag.Usage() + os.Exit(1) + } + + url := flag.Arg(0) + ":" + strconv.Itoa(port) + request := "gemini://" + flag.Arg(0) + "/\r\n" + conf := tls.Config{ InsecureSkipVerify: true, } + log.Println("connecting to: " + url) + conn, err := tls.Dial("tcp", url, &conf) if err != nil { |