Update go-gemini dependency

This commit is contained in:
Adnan Maolood 2021-02-24 23:32:39 -05:00 committed by Drew DeVault
parent 60109be26f
commit edd4fe31f1
3 changed files with 19 additions and 16 deletions

2
go.mod
View file

@ -3,6 +3,6 @@ module git.sr.ht/~sircmpwn/kineto
go 1.15 go 1.15
require ( require (
git.sr.ht/~adnano/go-gemini v0.1.13 git.sr.ht/~adnano/go-gemini v0.1.17
git.sr.ht/~sircmpwn/getopt v0.0.0-20191230200459-23622cc906b3 git.sr.ht/~sircmpwn/getopt v0.0.0-20191230200459-23622cc906b3
) )

11
go.sum
View file

@ -1,5 +1,5 @@
git.sr.ht/~adnano/go-gemini v0.1.13 h1:vzKkkVrOzMpfJ1AAeE/PChg0Rw5Zf+9HrnwsgVxXUT4= git.sr.ht/~adnano/go-gemini v0.1.17 h1:CJ3tDaqAJQbOdVXmiPC/iXHt4lF/CRu2nxPNOPjHUBk=
git.sr.ht/~adnano/go-gemini v0.1.13/go.mod h1:If1VxEWcZDrRt5FeAFnGTcM2Ud1E3BXs3VJ5rnZWKq0= git.sr.ht/~adnano/go-gemini v0.1.17/go.mod h1:hQ75Y0i5jSFL+FQ7AzWVAYr5LQsaFC7v3ZviNyj46dY=
git.sr.ht/~sircmpwn/getopt v0.0.0-20191230200459-23622cc906b3 h1:4wDp4BKF7NQqoh73VXpZsB/t1OEhDpz/zEpmdQfbjDk= git.sr.ht/~sircmpwn/getopt v0.0.0-20191230200459-23622cc906b3 h1:4wDp4BKF7NQqoh73VXpZsB/t1OEhDpz/zEpmdQfbjDk=
git.sr.ht/~sircmpwn/getopt v0.0.0-20191230200459-23622cc906b3/go.mod h1:wMEGFFFNuPos7vHmWXfszqImLppbc0wEhh6JBfJIUgw= git.sr.ht/~sircmpwn/getopt v0.0.0-20191230200459-23622cc906b3/go.mod h1:wMEGFFFNuPos7vHmWXfszqImLppbc0wEhh6JBfJIUgw=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
@ -9,3 +9,10 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
golang.org/x/net v0.0.0-20210119194325-5f4716e94777 h1:003p0dJM77cxMSyCPFphvZf/Y5/NXf5fzg6ufd1/Oew=
golang.org/x/net v0.0.0-20210119194325-5f4716e94777/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=

22
main.go
View file

@ -1,6 +1,7 @@
package main package main
import ( import (
"context"
"fmt" "fmt"
"html/template" "html/template"
"io" "io"
@ -383,15 +384,12 @@ type GemtextHeading struct {
func proxyGemini(req gemini.Request, external bool, root *url.URL, func proxyGemini(req gemini.Request, external bool, root *url.URL,
w http.ResponseWriter, r *http.Request, css string) { w http.ResponseWriter, r *http.Request, css string) {
client := gemini.Client{
Timeout: 30 * time.Second,
}
if h := (url.URL{Host: req.Host}); h.Port() == "" { ctx, cancel := context.WithTimeout(r.Context(), 20*time.Second)
req.Host += ":1965" defer cancel()
}
resp, err := client.Do(&req) client := gemini.Client{}
resp, err := client.Do(ctx, &req)
if err != nil { if err != nil {
w.WriteHeader(http.StatusBadGateway) w.WriteHeader(http.StatusBadGateway)
fmt.Fprintf(w, "Gateway error: %v", err) fmt.Fprintf(w, "Gateway error: %v", err)
@ -479,7 +477,7 @@ func proxyGemini(req gemini.Request, external bool, root *url.URL,
lang := params["lang"] lang := params["lang"]
w.Header().Add("Content-Type", "text/html") w.Header().Add("Content-Type", "text/html")
ctx := &GemtextContext{ gemctx := &GemtextContext{
CSS: css, CSS: css,
External: external, External: external,
Resp: resp, Resp: resp,
@ -491,16 +489,16 @@ func proxyGemini(req gemini.Request, external bool, root *url.URL,
var title bool var title bool
gemini.ParseLines(resp.Body, func(line gemini.Line) { gemini.ParseLines(resp.Body, func(line gemini.Line) {
ctx.Lines = append(ctx.Lines, line) gemctx.Lines = append(gemctx.Lines, line)
if !title { if !title {
if h, ok := line.(gemini.LineHeading1); ok { if h, ok := line.(gemini.LineHeading1); ok {
ctx.Title = string(h) gemctx.Title = string(h)
title = true title = true
} }
} }
}) })
err = gemtextPage.Execute(w, ctx) err = gemtextPage.Execute(w, gemctx)
if err != nil { if err != nil {
w.WriteHeader(http.StatusInternalServerError) w.WriteHeader(http.StatusInternalServerError)
fmt.Fprintf(w, "%v", err) fmt.Fprintf(w, "%v", err)
@ -573,7 +571,6 @@ func main() {
req.URL.Scheme = root.Scheme req.URL.Scheme = root.Scheme
req.URL.Host = root.Host req.URL.Host = root.Host
req.URL.Path = r.URL.Path req.URL.Path = r.URL.Path
req.Host = root.Host
req.URL.RawQuery = r.URL.RawQuery req.URL.RawQuery = r.URL.RawQuery
proxyGemini(req, false, root, w, r, css) proxyGemini(req, false, root, w, r, css)
})) }))
@ -607,7 +604,6 @@ func main() {
req.URL.Scheme = "gemini" req.URL.Scheme = "gemini"
req.URL.Host = path[2] req.URL.Host = path[2]
req.URL.Path = "/" + path[3] req.URL.Path = "/" + path[3]
req.Host = path[2]
req.URL.RawQuery = r.URL.RawQuery req.URL.RawQuery = r.URL.RawQuery
log.Printf("%s (external) %s%s", r.Method, r.URL.Host, r.URL.Path) log.Printf("%s (external) %s%s", r.Method, r.URL.Host, r.URL.Path)
proxyGemini(req, true, root, w, r, css) proxyGemini(req, true, root, w, r, css)