initial push

This commit is contained in:
Simon Kellet 2024-07-06 15:58:46 +01:00
parent 332b5f9798
commit 99e725b628
9 changed files with 92 additions and 0 deletions

BIN
agate Executable file

Binary file not shown.

68
client.go Normal file
View File

@ -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)
}

1
content/index.gmi Normal file
View File

@ -0,0 +1 @@
# Hello

3
content/test.gmi Normal file
View File

@ -0,0 +1,3 @@
# Hello there
## This is a Gemini file

BIN
go-gem-viewer Executable file

Binary file not shown.

3
go.mod Normal file
View File

@ -0,0 +1,3 @@
module go-gem-viewer
go 1.22.3

7
main.go Normal file
View File

@ -0,0 +1,7 @@
package main
func main() {
fullUrl := "gemini://localhost/test.gmi"
Fetch(fullUrl)
}

5
run.sh Executable file
View File

@ -0,0 +1,5 @@
#!/bin/bash
set -xe
go build . && ./go-gem-viewer

5
start-agate.sh Executable file
View File

@ -0,0 +1,5 @@
#!/bin/bash
set -xe
./agate --content ./content