1
0
mirror of https://github.com/makew0rld/amfora.git synced 2024-07-07 16:44:14 -04:00
amfora/client/client.go

34 lines
763 B
Go
Raw Normal View History

2020-06-18 16:54:48 -04: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 16:54:48 -04:00
"github.com/makeworld-the-better-one/go-gemini"
2020-08-27 22:40:40 -04:00
"github.com/spf13/viper"
2020-06-18 16:54:48 -04: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-27 22:40:40 -04:00
var res *gemini.Response
var err error
if config.Proxy == nil {
2020-08-27 22:40:40 -04:00
res, err = gemini.Fetch(u)
} else {
res, err = gemini.FetchWithHost(viper.GetString("a-general.proxy"), u)
}
2020-06-18 16:54:48 -04:00
if err != nil {
2020-06-19 14:05:05 -04:00
return nil, err
2020-06-18 16:54:48 -04:00
}
parsed, _ := url.Parse(u)
ok := handleTofu(parsed.Hostname(), parsed.Port(), res.Cert)
2020-06-18 16:54:48 -04:00
if !ok {
return res, ErrTofu
2020-06-18 16:54:48 -04:00
}
return res, err
2020-06-18 16:54:48 -04:00
}