initial push
This commit is contained in:
parent
332b5f9798
commit
99e725b628
68
client.go
Normal file
68
client.go
Normal 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
1
content/index.gmi
Normal file
@ -0,0 +1 @@
|
||||
# Hello
|
3
content/test.gmi
Normal file
3
content/test.gmi
Normal file
@ -0,0 +1,3 @@
|
||||
# Hello there
|
||||
|
||||
## This is a Gemini file
|
BIN
go-gem-viewer
Executable file
BIN
go-gem-viewer
Executable file
Binary file not shown.
7
main.go
Normal file
7
main.go
Normal file
@ -0,0 +1,7 @@
|
||||
package main
|
||||
|
||||
func main() {
|
||||
fullUrl := "gemini://localhost/test.gmi"
|
||||
Fetch(fullUrl)
|
||||
|
||||
}
|
5
start-agate.sh
Executable file
5
start-agate.sh
Executable file
@ -0,0 +1,5 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -xe
|
||||
|
||||
./agate --content ./content
|
Loading…
x
Reference in New Issue
Block a user