move pageviews struct to API endpoint

This commit is contained in:
Danny van Kooten 2017-01-13 16:46:09 +01:00
parent 8ebe401684
commit 3a46eda0ee
2 changed files with 9 additions and 10 deletions

View File

@ -5,9 +5,15 @@ import (
"github.com/dannyvankooten/ana/count"
"github.com/dannyvankooten/ana/db"
"github.com/dannyvankooten/ana/models"
)
type pageviews struct {
Hostname string
Path string
Count int
CountUnique int
}
// URL: /api/pageviews
var GetPageviewsHandler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
before, after := getRequestedPeriods(r)
@ -32,9 +38,9 @@ var GetPageviewsHandler = http.HandlerFunc(func(w http.ResponseWriter, r *http.R
checkError(err)
defer rows.Close()
results := make([]models.Pageviews, 0)
results := make([]pageviews, 0)
for rows.Next() {
var p models.Pageviews
var p pageviews
err = rows.Scan(&p.Hostname, &p.Path, &p.Count, &p.CountUnique)
checkError(err)
results = append(results, p)

View File

@ -13,13 +13,6 @@ type Pageview struct {
Timestamp string
}
type Pageviews struct {
Hostname string
Path string
Count int
CountUnique int
}
func (pv *Pageview) Save(conn *sql.DB) error {
// prepare statement for inserting data
stmt, err := conn.Prepare(`INSERT INTO pageviews (