package main import ( "bufio" "crypto/tls" "flag" "gemini" "os" ) func usage() { println("Usage: " + os.Args[0] + " [options] url(s)") flag.PrintDefaults() } func create_output(path string) *os.File { switch path { case "": return os.Stdout default: if output, err := os.Create(path); err != nil { panic(err) } else { return output } } } func list_requests(path string) []string { if path == "" { return nil } file, err := os.Open(path) if err != nil { println("Error reading input: " + err.Error()) return nil } defer file.Close() var lines []string scanner := bufio.NewScanner(file) for scanner.Scan() { lines = append(lines, scanner.Text()) } return lines } func main() { var ( f_host string f_port int = gemini.GeminiPort f_input string f_output string ) flag.Usage = usage flag.StringVar(&f_host, "host", f_host, "server host name") flag.IntVar(&f_port, "port", f_port, "server port number") flag.StringVar(&f_input, "i", f_input, "read urls from file") flag.StringVar(&f_output, "o", f_output, "write output to path") flag.Parse() requests := append(list_requests(f_input), flag.Args()...) if len(requests) == 0 { println("No work to do") flag.Usage() os.Exit(1) } output := create_output(f_output) conf := tls.Config{ MinVersion: tls.VersionTLS12, InsecureSkipVerify: true, } for _, request := range requests { if conn, err := gemini.Parse(request, f_host, f_port); err != nil { println("Error parsing request: " + request) println(err.Error()) } else if err := conn.Get(&conf, output); err != nil { println(err.Error()) } } }