1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
package main
import (
"crypto/tls"
"flag"
"fmt"
"log"
"os"
"strconv"
)
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 {
panic("failed to connect: " + err.Error())
} else {
log.Println("connected to " + url)
}
defer conn.Close()
n, err := conn.Write([]byte(request))
if err != nil {
log.Println(n, err)
return
}
buf := make([]byte, 1024)
for {
n, err = conn.Read(buf)
if err != nil {
log.Println(n, err)
return
} else {
println(string(buf[:n]))
}
if n == 0 {
break
}
}
}
|