diff --git a/agate b/agate new file mode 100755 index 0000000..8bd0d4b Binary files /dev/null and b/agate differ diff --git a/client.go b/client.go new file mode 100644 index 0000000..a4b6cba --- /dev/null +++ b/client.go @@ -0,0 +1,68 @@ +package main + +import ( + "crypto/tls" + "fmt" + "log" + "net/url" +) + +type Responce struct { + Status string + Meta string +} + +type Request struct { + URL string +} + +type Client struct { + InsecureSkipVerify bool +} + +var config = tls.Config{ + InsecureSkipVerify: true, +} + +var DefaultClient = &Client{} + +func Fetch(args ...string) { + DefaultPort := "1965" + if len(args) < 2 { + DefaultClient.Fetch(args[0], DefaultPort) + } + if len(args) > 2 { + log.Fatal("too many args passed, just want URL and PORT") + } + if len(args) == 2 { + DefaultClient.Fetch(args[0], args[1]) + } +} + +func (c Client) Fetch(URL string, port string) { + conn := c.connect(URL, port) + defer conn.Close() + c.sendRequest(conn, URL) +} + +func (c Client) connect(URL string, port string) *tls.Conn { + parsedURL, err := url.Parse(URL) + if err != nil { + log.Fatal(err) + } + + conn, err := tls.Dial("tcp", parsedURL.Host+":"+port, &config) + if err != nil { + log.Fatalf("failed to connect: %v", err) + } + return conn +} + +func (c Client) sendRequest(connection *tls.Conn, requestURL string) { + CRLF := "\r\n" + reqSize, err := connection.Write([]byte(requestURL + CRLF)) + if err != nil { + log.Fatal(err) + } + fmt.Printf("request (%d bytes) sent...\n", reqSize) +} diff --git a/content/index.gmi b/content/index.gmi new file mode 100644 index 0000000..fec5601 --- /dev/null +++ b/content/index.gmi @@ -0,0 +1 @@ +# Hello diff --git a/content/test.gmi b/content/test.gmi new file mode 100644 index 0000000..cdb23cf --- /dev/null +++ b/content/test.gmi @@ -0,0 +1,3 @@ +# Hello there + +## This is a Gemini file diff --git a/go-gem-viewer b/go-gem-viewer new file mode 100755 index 0000000..45e7599 Binary files /dev/null and b/go-gem-viewer differ diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..3c319ca --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module go-gem-viewer + +go 1.22.3 diff --git a/main.go b/main.go new file mode 100644 index 0000000..76f463b --- /dev/null +++ b/main.go @@ -0,0 +1,7 @@ +package main + +func main() { + fullUrl := "gemini://localhost/test.gmi" + Fetch(fullUrl) + +} diff --git a/run.sh b/run.sh new file mode 100755 index 0000000..0ecd4b3 --- /dev/null +++ b/run.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +set -xe + +go build . && ./go-gem-viewer \ No newline at end of file diff --git a/start-agate.sh b/start-agate.sh new file mode 100755 index 0000000..e830924 --- /dev/null +++ b/start-agate.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +set -xe + +./agate --content ./content \ No newline at end of file