1
0
mirror of https://github.com/makew0rld/amfora.git synced 2024-07-03 20:25:24 +00:00
amfora/client/client.go

34 lines
765 B
Go
Raw Normal View History

2020-06-18 20:54:48 +00:00
// Package client retrieves data over Gemini and implements a TOFU system.
package client
import (
"net/url"
"github.com/makeworld-the-better-one/amfora/config"
2020-06-18 20:54:48 +00:00
"github.com/makeworld-the-better-one/go-gemini"
2020-08-28 02:40:40 +00:00
"github.com/spf13/viper"
2020-06-18 20:54:48 +00:00
)
// Fetch returns response data and an error.
// The error text is human friendly and should be displayed.
func Fetch(u string) (*gemini.Response, error) {
2020-08-28 02:40:40 +00:00
var res *gemini.Response
var err error
2020-09-01 18:55:52 +00:00
if config.GemProxy == nil {
2020-08-28 02:40:40 +00:00
res, err = gemini.Fetch(u)
} else {
2020-09-01 18:55:52 +00:00
res, err = gemini.FetchWithHost(viper.GetString("proxies.gemini"), u)
2020-08-28 02:40:40 +00:00
}
2020-06-18 20:54:48 +00:00
if err != nil {
2020-06-19 18:05:05 +00:00
return nil, err
2020-06-18 20:54:48 +00:00
}
parsed, _ := url.Parse(u)
ok := handleTofu(parsed.Hostname(), parsed.Port(), res.Cert)
2020-06-18 20:54:48 +00:00
if !ok {
return res, ErrTofu
2020-06-18 20:54:48 +00:00
}
return res, err
2020-06-18 20:54:48 +00:00
}