Implement Read Only mode

This commit is contained in:
Las Zenow 2017-05-21 10:16:16 +00:00
parent 6464d92dd4
commit e1bd235785
19 changed files with 544 additions and 335 deletions

View file

@ -22,27 +22,30 @@ type handler struct {
w http.ResponseWriter
r *http.Request
sess *Session
db *database.DB
store *storage.Store
db database.DB
store storage.Store
template *Template
hostname string
ro bool
}
type StatsGatherer struct {
db *database.DB
store *storage.Store
db database.DB
store storage.Store
template *Template
hostname string
channel chan statsRequest
ro bool
}
func InitStats(database *database.DB, store *storage.Store, hostname string, template *Template) *StatsGatherer {
func InitStats(database database.DB, store storage.Store, hostname string, template *Template, ro bool) *StatsGatherer {
sg := StatsGatherer{
channel: make(chan statsRequest, statsChanSize),
db: database,
store: store,
template: template,
hostname: hostname,
ro: ro,
}
go sg.worker()
@ -62,6 +65,7 @@ func (sg StatsGatherer) Gather(function func(handler)) func(http.ResponseWriter,
w: w,
r: r,
sess: GetSession(r, db),
ro: sg.ro,
}
defer h.db.Close()
@ -136,7 +140,7 @@ func monthlyLabel(date time.Time) string {
return date.Month().String()
}
func getVisits(funcLabel func(time.Time) string, db *database.DB, visitType database.VisitType) []visitData {
func getVisits(funcLabel func(time.Time) string, db database.DB, visitType database.VisitType) []visitData {
var visits []visitData
visit, err := db.GetVisits(visitType)