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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
// 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"
)
// NewFeed will fetch and create a new core.Feed given any url
func NewFeed(remoteURL *url.URL, title string) (*core.Feed, error) {
switch remoteURL.Scheme {
case "gemini":
return newGeminiFeed(remoteURL, title)
case "http", "https":
return newHTTPFeed(remoteURL, title)
case "gopher", "gophers":
return newGopherFeed(remoteURL, title)
default:
return nil, fmt.Errorf("Unsupported protocol '%s'", remoteURL.Scheme)
}
}
// NewPage will fetch and create a new core.Page given any url
func NewPage(remoteURL *url.URL, title string) (*core.Page, error) {
switch remoteURL.Scheme {
case "gemini":
return newGeminiPage(remoteURL, title)
case "http", "https":
return newHTTPPage(remoteURL, title)
case "gopher", "gophers":
return newGopherPage(remoteURL, title)
default:
return nil, fmt.Errorf("Unsupported protocol '%s'", remoteURL.Scheme)
}
}
// UpdateFeed will check an existing core.Feed for updates
func UpdateFeed(f *core.Feed) error {
switch f.FeedLink.Scheme {
case "gemini":
// return updateGeminiFeed(f)
// TODO
fallthrough
case "http", "https":
// return updateHTTPFeed(f)
// TODO
fallthrough
case "gopher", "gophers":
// return updateGopherFeed(f)
// TODO
fallthrough
default:
return fmt.Errorf("Unsupported protocol '%s'", f.FeedLink.Scheme)
}
return nil
}
// UpdatePage will check an existing core.Page for updages
func UpdatePage(p *core.Page) error {
switch p.Link.Scheme {
case "gemini":
return updateGeminiPage(p)
case "http", "https":
return updateHTTPPage(p)
case "gopher", "gophers":
return updateGopherPage(p)
default:
return fmt.Errorf("Unsupported protocol '%s'", p.Link.Scheme)
}
return nil
}
|