aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoraqua <aqua@iserlohn-fortress.net>2021-07-29 18:02:03 +0300
committeraqua <aqua@iserlohn-fortress.net>2021-07-29 18:02:03 +0300
commit3c8887d2fa99b16f7117a6806b00a96565487c12 (patch)
treefa3e8a339ba0ca16b878f9d922206d1cd5dcdca2
parentAdd readme and license (diff)
downloadgemcat-3c8887d2fa99b16f7117a6806b00a96565487c12.tar.xz
Add -o (output) flag
-rw-r--r--gemini.go1
-rw-r--r--main.go34
2 files changed, 25 insertions, 10 deletions
diff --git a/gemini.go b/gemini.go
index 8594de4..79a7c97 100644
--- a/gemini.go
+++ b/gemini.go
@@ -37,6 +37,7 @@ func NewGeminiConn(request string, port int) (*GeminiConn, error) {
}
conf := tls.Config{
+ MinVersion: tls.VersionTLS12,
InsecureSkipVerify: true,
}
diff --git a/main.go b/main.go
index 22d9fbf..a4c2190 100644
--- a/main.go
+++ b/main.go
@@ -7,35 +7,49 @@ import (
"os"
)
-var host = ""
-var port = GeminiPort
-
func usage() {
fmt.Printf("Usage: %s [options] url\n", os.Args[0])
flag.PrintDefaults()
}
func main() {
+ flags := struct {
+ host string
+ port int
+ output string
+ }{
+ host: "",
+ port: GeminiPort,
+ output: "",
+ }
+
flag.Usage = usage
- flag.StringVar(&host, "h", host, "server host name")
- flag.StringVar(&host, "host", host, "server host name")
- flag.IntVar(&port, "p", port, "server port number")
- flag.IntVar(&port, "port", port, "server port number")
+ flag.StringVar(&flags.host, "h", flags.host, "server host name")
+ flag.IntVar(&flags.port, "p", flags.port, "server port number")
+ flag.StringVar(&flags.output, "o", flags.output, "write output to path")
flag.Parse()
if flag.NArg() != 1 {
- fmt.Printf("Got %d arguments, expected 1\n", flag.NArg())
+ fmt.Printf("Error: Got %d arguments, expected 1\n", flag.NArg())
flag.Usage()
os.Exit(1)
}
- conn, err := NewGeminiConn(flag.Arg(0), port)
+ conn, err := NewGeminiConn(flag.Arg(0), flags.port)
if err != nil {
log.Fatalf("Error parsing hostname: %s\n", err.Error())
}
log.Printf("connecting to: %s\n", conn.host)
- err = conn.Get(FormatRequest(flag.Arg(0)), os.Stdout)
+ var output = os.Stdout
+ if flags.output != "" {
+ output, err = os.Create(flags.output)
+ if err != nil {
+ log.Fatalf("Error creating file: %s\n", err.Error())
+ }
+ }
+
+ err = conn.Get(FormatRequest(flag.Arg(0)), output)
if err != nil {
log.Fatalf("Error: %s\n", err.Error())
}