/
stats-controller.go
58 lines (44 loc) · 1.57 KB
/
stats-controller.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
package report
import (
"encoding/json"
"net/http"
"github.com/gorilla/mux"
)
func MonthlyStatsIndex(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-type", "application/json;charset=UTF-8")
w.WriteHeader(http.StatusOK)
stats := AllMonthlyStats()
err := json.NewEncoder(w).Encode(stats)
if err != nil {
TheLogger().LogError(log_name_monthly_stat, "problem with indexation.", err)
} else {
TheLogger().LogInfo(log_name_monthly_stat, "request GET : "+r.RequestURI)
}
}
func MonthlyStatShowByDate(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-type", "application/json;charset=UTF-8")
vars := mux.Vars(r)
archive_date := vars["archive_date"]
w.WriteHeader(http.StatusOK)
stats := FindMonthlyStatByDate(archive_date)
err := json.NewEncoder(w).Encode(stats)
if err != nil {
TheLogger().LogError(log_name_monthly_stat, "problem with encoder.", err)
} else {
TheLogger().LogInfo(log_name_monthly_stat, "request GET : "+r.RequestURI)
}
}
func AutoMonthlyStatCreate(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-type", "application/json;charset=UTF-8")
w.WriteHeader(http.StatusOK)
AutoNewMonthlyStat()
TheLogger().LogInfo(log_name_monthly_stat, "request GET : "+r.RequestURI)
}
func ForceMonthlyStatCreate(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-type", "application/json;charset=UTF-8")
vars := mux.Vars(r)
archive_date := vars["archive_date"]
w.WriteHeader(http.StatusOK)
AutoNewMonthlyStat(archive_date)
TheLogger().LogInfo(log_name_monthly_stat, "request GET : "+r.RequestURI)
}