fathom/ana.go

53 lines
2.0 KiB
Go
Raw Normal View History

package main
import (
"net/http"
2016-11-22 20:02:06 +00:00
"os"
2016-11-22 21:33:50 +00:00
"log"
"github.com/dannyvankooten/ana/core"
"github.com/dannyvankooten/ana/api"
2016-11-22 19:57:16 +00:00
"github.com/gorilla/mux"
2016-11-22 20:02:06 +00:00
"github.com/gorilla/handlers"
2016-11-22 21:33:50 +00:00
"github.com/joho/godotenv"
seed "github.com/dannyvankooten/ana/db"
)
func main() {
// load .env file
2016-11-22 21:33:50 +00:00
err := godotenv.Load()
if err != nil {
log.Fatal("Error loading .env file")
}
db := core.SetupDatabaseConnection()
defer db.Close()
// seed 1000 records
seed.Seed(100)
2016-12-05 16:16:14 +00:00
2016-11-22 21:33:50 +00:00
r := mux.NewRouter()
2016-11-22 19:57:16 +00:00
2016-11-22 21:33:50 +00:00
// register routes
r.HandleFunc("/collect", api.CollectHandler).Methods("GET")
r.Handle("/api/session", api.Login).Methods("POST")
r.Handle("/api/session", api.Logout).Methods("DELETE")
r.Handle("/api/visits/count", api.Authorize(api.GetVisitsCountHandler)).Methods("GET")
r.Handle("/api/visits/count/group/{period}", api.Authorize(api.GetVisitsPeriodCountHandler)).Methods("GET")
r.Handle("/api/visits/count/realtime", api.Authorize(api.GetVisitsRealtimeCountHandler)).Methods("GET")
2016-11-22 21:33:50 +00:00
r.Handle("/api/visits", api.Authorize(api.GetVisitsHandler)).Methods("GET")
r.Handle("/api/pageviews/count", api.Authorize(api.GetPageviewsCountHandler)).Methods("GET")
r.Handle("/api/pageviews/count/group/{period}", api.Authorize(api.GetPageviewsPeriodCountHandler)).Methods("GET")
2016-11-22 21:33:50 +00:00
r.Handle("/api/pageviews", api.Authorize(api.GetPageviewsHandler)).Methods("GET")
r.Handle("/api/languages", api.Authorize(api.GetLanguagesHandler)).Methods("GET")
r.Handle("/api/screen-resolutions", api.Authorize(api.GetScreenResolutionsHandler)).Methods("GET")
r.Handle("/api/countries", api.Authorize(api.GetCountriesHandler)).Methods("GET")
2016-11-24 13:37:41 +00:00
r.Handle("/api/browsers", api.Authorize(api.GetBrowsersHandler)).Methods("GET")
2016-11-22 21:33:50 +00:00
r.PathPrefix("/static/").Handler(http.StripPrefix("/static/", http.FileServer(http.Dir("./static/"))))
r.Path("/tracker.js").Handler(http.FileServer(http.Dir("./static/js/")))
2016-11-22 21:33:50 +00:00
r.Handle("/", http.FileServer(http.Dir("./views/")))
2016-11-22 19:57:16 +00:00
2016-11-22 21:33:50 +00:00
http.ListenAndServe(":8080", handlers.LoggingHandler(os.Stdout, r))
}