/
actions.go
113 lines (87 loc) · 2.42 KB
/
actions.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package main
import (
"html/template"
// "io"
// "code.google.com/p/goconf/conf"
"fmt"
// "github.com/gorilla/mux"
"github.com/DeyV/go-newsagg/category"
"net/http"
)
func init() {
HandleFunc("/", actionHome)
HandleFunc("/test", actionTest)
// HandleFunc("/k", actionCategories)
HandleFunc("/k", actionCategoryList)
HandleFunc("/k/latest", actionCategories)
}
func actionHome(w http.ResponseWriter, req *http.Request) {
var templActionHome *template.Template = template.Must(
template.ParseGlob("templates/home/*.html"))
lay := getLayoutTemplates()
wr := &HtmlContainer{}
// templActionHome.Funcs(template.FuncMap{"len": Len})
data := HtmlAssigner{
"List": getEntryList("", 10),
"Test": "Test",
}
err := templActionHome.Execute(wr, data)
if err != nil {
fmt.Errorf("%v", err)
}
lay.New("title").Parse("Najnowsze wpisy - " + config.GetStringDef("page", "title", ""))
err = lay.Execute(w, wr.getHtml())
if err != nil {
fmt.Errorf("%v", err)
}
}
func actionCategoryList(w http.ResponseWriter, req *http.Request) {
Id := req.URL.Query().Get("id")
fmt.Println(Id)
// // param := req.Vars()
// catId, ok := param["id"]
// if ok == nil {
// catId = 0
// }
var templActionHome *template.Template = template.Must(
template.ParseGlob("templates/home/*.html"))
lay := getLayoutTemplates()
wr := &HtmlContainer{}
// templActionHome.Funcs(template.FuncMap{"len": Len})
data := HtmlAssigner{
"List": getEntryList("", 10),
"Test": "Test",
}
err := templActionHome.Execute(wr, data)
if err != nil {
fmt.Errorf("%v", err)
}
lay.New("title").Parse("Najnowsze wpisy - " + config.GetStringDef("page", "title", ""))
err = lay.Execute(w, wr.getHtml())
if err != nil {
fmt.Errorf("%v", err)
}
}
func actionCategories(w http.ResponseWriter, req *http.Request) {
var templActionCategories *template.Template = template.Must(
template.ParseGlob("templates/categories/*.html"))
wr := &HtmlContainer{}
// templActionHome.Funcs(template.FuncMap{"len": Len})
data := HtmlAssigner{
"List": category.GetTagCloud(),
"Test": "Test",
}
err := templActionCategories.Execute(wr, data)
if err != nil {
fmt.Errorf("%v", err)
}
lay := getLayoutTemplates()
lay.New("title").Parse("Lista Kategorii - " + config.GetStringDef("page", "title", ""))
err = lay.Execute(w, wr.getHtml())
if err != nil {
fmt.Errorf("%v", err)
}
}
func actionTest(w http.ResponseWriter, req *http.Request) {
fmt.Fprint(w, "test")
}