31 lines
493 B
Go
31 lines
493 B
Go
package repo
|
|
|
|
import (
|
|
"time"
|
|
|
|
_ "github.com/go-sql-driver/mysql"
|
|
)
|
|
|
|
type Pageview struct {
|
|
Id int64
|
|
IPAddress string
|
|
UserAgent string
|
|
Timestamp time.Time
|
|
}
|
|
|
|
func AddPageview(pageview Pageview) (int64, error) {
|
|
db := getDB()
|
|
|
|
result, err := db.Exec("INSERT INTO pageview (ip_address, user_agent) VALUES (?, ?)", pageview.IPAddress, pageview.UserAgent)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
|
|
id, err := result.LastInsertId()
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
|
|
return id, nil
|
|
}
|