-
Notifications
You must be signed in to change notification settings - Fork 0
/
get-source.go
67 lines (53 loc) · 1.42 KB
/
get-source.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
package rest
import (
"github.com/boggydigital/kvas"
"github.com/boggydigital/nod"
"github.com/boggydigital/novus/data"
"net/http"
)
func GetSource(w http.ResponseWriter, r *http.Request) {
// GET /source?id
id := r.URL.Query().Get("id")
sources, err := data.LoadSources()
if err != nil {
http.Error(w, nod.Error(err).Error(), http.StatusInternalServerError)
return
}
srcIpv := data.SourcesIdPropertyValues(sources)
properties := []string{
data.GetContentErrorsProperty,
data.MatchContentErrorsProperty,
data.ReduceErrorsProperty,
data.CurrentElementsProperty,
data.AddedElementsProperty,
data.RemovedElementsProperty,
data.SourceURLProperty}
rdx, err := kvas.NewReduxReader(data.AbsReduxDir(), properties...)
if err != nil {
http.Error(w, nod.Error(err).Error(), http.StatusInternalServerError)
return
}
ids := make(map[string]interface{})
for _, p := range properties {
for _, pid := range rdx.Keys(p) {
ids[pid] = nil
}
}
for pid := range ids {
for _, p := range properties {
if srcIpv[pid] == nil {
srcIpv[pid] = make(map[string][]string)
}
srcIpv[pid][p], _ = rdx.GetAllValues(p, pid)
if srcIpv[pid][p] == nil {
srcIpv[pid][p] = make([]string, 0)
}
}
}
rdxProxy := kvas.ReduxProxy(srcIpv)
DefaultHeaders(w)
if err := app.RenderItem(id, nil, rdxProxy, w); err != nil {
http.Error(w, nod.Error(err).Error(), http.StatusInternalServerError)
return
}
}