Do not expose the database at instance.DB anymore.

This commit is contained in:
A. Svensson 2016-06-19 15:32:18 +02:00
parent d2af505b0c
commit 3fb5a6a3e9
3 changed files with 11 additions and 11 deletions

View File

@ -11,11 +11,10 @@ import (
type D map[string]interface{}
type Instance struct {
Debug bool
DB *DB
Config *Config
Debug bool
addr string
db *DB
router *mux.Router
tmpls *template.Template
}

View File

@ -18,7 +18,7 @@ type RawServerData struct {
func (i *Instance) UpdateServers() {
reset()
tx := i.DB.NewTransaction()
tx := i.db.NewTransaction()
if i.Debug {
fmt.Println("\nPolling servers...")
@ -76,7 +76,7 @@ func isupdated(title string) bool {
func (i *Instance) get_old_servers() []*RawServerData {
var tmp []*RawServerData
for _, old := range i.DB.GetOldServers(Now()) {
for _, old := range i.db.GetOldServers(Now()) {
s := RawServerData{
Title: old.Title,
Game_url: old.GameUrl,

View File

@ -25,9 +25,10 @@ func New(debug bool, path string) (*Instance, error) {
db.InitSchema()
i := Instance{
Debug: debug,
DB: db,
Config: c,
Debug: debug,
db: db,
}
return &i, nil
@ -114,7 +115,7 @@ func (i *Instance) page_404(w http.ResponseWriter, r *http.Request) {
}
func (i *Instance) page_index(w http.ResponseWriter, r *http.Request) {
servers := i.DB.AllServers()
servers := i.db.AllServers()
i.tmpls.ExecuteTemplate(w, "page_index.html", D{
"pagetitle": "Index",
"servers": servers,
@ -132,7 +133,7 @@ func (i *Instance) page_server(w http.ResponseWriter, r *http.Request) {
return
}
s, err := i.DB.GetServer(int(id))
s, err := i.db.GetServer(int(id))
if err != nil {
i.page_404(w, r)
return
@ -153,8 +154,8 @@ func (i *Instance) page_server(w http.ResponseWriter, r *http.Request) {
i.tmpls.ExecuteTemplate(w, "page_server.html", D{
"pagetitle": s.Title,
"server": s,
"weekhistory": i.DB.GetServerPopulation(int(id), time.Duration(7*24+12)*time.Hour),
"monthhistory": i.DB.GetServerPopulation(int(id), time.Duration(31*24)*time.Hour),
"weekhistory": i.db.GetServerPopulation(int(id), time.Duration(7*24+12)*time.Hour),
"monthhistory": i.db.GetServerPopulation(int(id), time.Duration(31*24)*time.Hour),
"weekdayavg": weekdayavg,
})
}