summaryrefslogtreecommitdiff
path: root/fetch/fetch.go
blob: 6e9e7a0288a2ea6dad58c6a17cc3072bae0d1d83 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// 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, title)
	case "http", "https":
		return httpFeed(data, remote, title)
	case "gopher", "gophers":
		return gopherFeed(data, remote, 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, title)
	case "http", "https":
		return httpPage(data, remote, title)
	case "gopher", "gophers":
		return gopherPage(data, remote, title)
	default:
		return fmt.Errorf("Unsupported protocol '%s'", remote.Scheme)
	}
}