This repository has been archived by the owner on Nov 7, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
links.go
77 lines (67 loc) · 1.47 KB
/
links.go
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
package core
import (
"github.com/datatogether/sqlutil"
)
// ReadDstLinks returns all links that specify a given url as src
func ReadDstLinks(db sqlutil.Queryable, src *Url) ([]*Link, error) {
res, err := db.Query(qUrlDstLinks, src.Url)
if err != nil {
return nil, err
}
defer res.Close()
links := make([]*Link, 0)
for res.Next() {
dst := &Url{}
if err := dst.UnmarshalSQL(res); err != nil {
return nil, err
}
l := &Link{
Src: src,
Dst: dst,
}
links = append(links, l)
}
return links, nil
}
// ReadSrcLinks returns all links that specify a given url as dst
func ReadSrcLinks(db sqlutil.Queryable, dst *Url) ([]*Link, error) {
res, err := db.Query(qUrlSrcLinks, dst.Url)
if err != nil {
return nil, err
}
defer res.Close()
links := make([]*Link, 0)
for res.Next() {
src := &Url{}
if err := src.UnmarshalSQL(res); err != nil {
return nil, err
}
l := &Link{
Src: src,
Dst: dst,
}
links = append(links, l)
}
return links, nil
}
// ReadDstContentLinks returns a list of links that specify a gien url as src that are content urls
func ReadDstContentLinks(db sqlutil.Queryable, src *Url) ([]*Link, error) {
res, err := db.Query(qUrlDstContentLinks, src.Url)
if err != nil {
return nil, err
}
defer res.Close()
links := make([]*Link, 0)
for res.Next() {
dst := &Url{}
if err := dst.UnmarshalSQL(res); err != nil {
return nil, err
}
l := &Link{
Src: src,
Dst: dst,
}
links = append(links, l)
}
return links, nil
}