2020-06-18 16:54:48 -04:00
|
|
|
// Package client retrieves data over Gemini and implements a TOFU system.
|
|
|
|
package client
|
|
|
|
|
|
|
|
import (
|
2020-06-19 23:44:04 -04:00
|
|
|
"net/url"
|
|
|
|
|
2020-06-18 16:54:48 -04:00
|
|
|
"github.com/makeworld-the-better-one/go-gemini"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Fetch returns response data and an error.
|
|
|
|
// The error text is human friendly and should be displayed.
|
2020-06-19 23:44:04 -04:00
|
|
|
func Fetch(u string) (*gemini.Response, error) {
|
2020-06-24 13:31:01 -04:00
|
|
|
res, err := gemini.Fetch(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
|
|
|
}
|
2020-06-19 23:44:04 -04:00
|
|
|
|
|
|
|
parsed, _ := url.Parse(u)
|
2020-06-24 13:31:01 -04:00
|
|
|
ok := handleTofu(parsed.Hostname(), parsed.Port(), res.Cert)
|
2020-06-18 16:54:48 -04:00
|
|
|
if !ok {
|
2020-06-24 13:31:01 -04:00
|
|
|
return res, ErrTofu
|
2020-06-18 16:54:48 -04:00
|
|
|
}
|
2020-06-24 13:31:01 -04:00
|
|
|
return res, err
|
2020-06-18 16:54:48 -04:00
|
|
|
}
|