45 lines
1.3 KiB
Go
45 lines
1.3 KiB
Go
// Copyright (C) 2021 nytpu
|
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
// For more license details, see LICENSE or <https://www.gnu.org/licenses/agpl-3.0.html>.
|
|
|
|
// package fetch implements routines for fetching gemini, gopher, and http
|
|
// resources and parsing feed formats
|
|
package fetch
|
|
|
|
import (
|
|
"fmt"
|
|
"net/url"
|
|
|
|
"golang.nytpu.com/comitium/core"
|
|
)
|
|
|
|
// Feed will fetch and insert a new core.Feed into a core.FullData given any url
|
|
// (or update if it's preexisting)
|
|
func Feed(data *core.FullData, remote *url.URL, title string) error {
|
|
switch remote.Scheme {
|
|
case "gemini":
|
|
return geminiFeed(data, remote.String(), title)
|
|
case "http", "https":
|
|
return httpFeed(data, remote.String(), title)
|
|
case "gopher", "gophers":
|
|
return gopherFeed(data, remote.String(), title)
|
|
default:
|
|
return fmt.Errorf("Unsupported protocol '%s'", remote.Scheme)
|
|
}
|
|
}
|
|
|
|
// Page will fetch and insert a new core.Page into a core.FullData given any url
|
|
// (or update if it's preexisting)
|
|
func Page(data *core.FullData, remote *url.URL, title string) error {
|
|
switch remote.Scheme {
|
|
case "gemini":
|
|
return geminiPage(data, remote.String(), title)
|
|
case "http", "https":
|
|
return httpPage(data, remote.String(), title)
|
|
case "gopher", "gophers":
|
|
return gopherPage(data, remote.String(), title)
|
|
default:
|
|
return fmt.Errorf("Unsupported protocol '%s'", remote.Scheme)
|
|
}
|
|
}
|