fathom/ana.go

34 lines
1.0 KiB
Go
Raw Normal View History

package main
import (
"net/http"
"github.com/dannyvankooten/ana/core"
"github.com/dannyvankooten/ana/api"
2016-11-22 19:57:16 +00:00
"github.com/gorilla/mux"
)
2016-11-21 16:36:25 +00:00
// TODO: Authentication.
func main() {
db := core.SetupDatabaseConnection()
defer db.Close()
2016-11-22 19:57:16 +00:00
r := mux.NewRouter()
// register routes
2016-11-22 19:57:16 +00:00
r.HandleFunc("/collect", api.CollectHandler).Methods("GET")
r.HandleFunc("/api/visits/count/day", api.GetVisitsDayCountHandler).Methods("GET")
r.HandleFunc("/api/visits/count/realtime", api.GetVisitsRealtimeCount).Methods("GET")
r.HandleFunc("/api/visits", api.GetVisitsHandler).Methods("GET")
r.HandleFunc("/api/pageviews", api.GetPageviewsHandler).Methods("GET")
r.PathPrefix("/static/").Handler(http.StripPrefix("/static/", http.FileServer(http.Dir("./static/"))))
r.Handle("/", http.FileServer(http.Dir("./views/")))
// r.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
// http.ServeFile(w, r, "./static/" + r.URL.Path[1:])
// })
http.ListenAndServe(":8080", r)
}