<commit_before>package main

import (
	"github.com/ant0ine/go-json-rest/rest"
	"github.com/jinzhu/gorm"
	_ "github.com/lib/pq"
	"github.com/yvasiyarov/go-metrics"
	"github.com/yvasiyarov/gorelic"
	"log"
	"net/http"
	"os"
	"time"
)

func main() {
	i := Impl{}
	i.InitDB()
	i.InitSchema()

	api := rest.NewApi()
	api.Use(rest.DefaultDevStack...)
	api.Use(&NewRelicMiddleware{
		License: os.Getenv("NEWRELIC_LICENCE_KEY"),
		Name:    "Puffin Event API",
		Verbose: true,
	})
	//api.Use(&rest.AccessLogJsonMiddleware{})
	router, err := rest.MakeRouter(
		rest.Post("/events", i.PostEvent),
		rest.Post("/installations", i.PostInstallation),
	)
	if err != nil {
		log.Fatal(err)
	}
	api.SetApp(router)
	log.Fatal(http.ListenAndServe("0.0.0.0:"+os.Getenv("PORT"), api.MakeHandler()))
}

type NewRelicMiddleware struct {
	License string
	Name    string
	Verbose bool
	agent   *gorelic.Agent
}

func (mw *NewRelicMiddleware) MiddlewareFunc(handler rest.HandlerFunc) rest.HandlerFunc {

	mw.agent = gorelic.NewAgent()
	mw.agent.NewrelicLicense = mw.License
	mw.agent.HTTPTimer = metrics.NewTimer()
	mw.agent.Verbose = mw.Verbose
	mw.agent.NewrelicName = mw.Name
	mw.agent.CollectHTTPStat = true
	mw.agent.Run()

	return func(writer rest.ResponseWriter, request *rest.Request) {

		handler(writer, request)

		// the timer middleware keeps track of the time
		startTime := request.Env["START_TIME"].(*time.Time)
		mw.agent.HTTPTimer.UpdateSince(*startTime)
	}
}

type Event struct {
	Id                          int64     `json:"id"`
	DeviceId                    string    `sql:"size:40" json:"deviceId"`
	MeasuredAt                  time.Time `json:"measuredAt"`
	Measurement                 string    `sql:"size:1024" json:"measurement"`
	Value                       float64   `json:"value"`
	Fields                      string    `sql:"size:1024" json:"fields"`
	Tags                        string    `sql:"size:1024" json:"tags"`
	Note                        string    `sql:"size:1024" json:"note"`
	CreatedAt                   time.Time `json:"createdAt"`
	UpdatedAt                   time.Time `json:"updatedAt"`
	DeletedAt                   time.Time `json:"-"`
	NotificationIntervalMinutes int64     `json:"notificationIntervalMinutes"`
	NotificationShownAt         time.Time `json:"notificationShownAt"`
	NotificationDismissedAt     time.Time `json:"notificationDismissedAt"`
	NotificationAcceptedAt      time.Time `json:"notificationAcceptedAt"`
}

type Installation struct {
	Id                  int64     `json:"id"`
	DeviceType          string    `sql:"size:40" json:"deviceType"`
	DeviceManufacturer  string    `sql:"size:40" json:"deviceManufacturer"`
	DeviceModel         string    `sql:"size:40" json:"deviceModel"`
	DeviceProduct       string    `sql:"size:40" json:"deviceProduct"`
	DeviceSdk           string    `sql:"size:40" json:"deviceSdk"`
	DeviceSystemLocale  string    `sql:"size:40" json:"deviceSystemLocale"`
	DeviceAdvertisingId string    `sql:"size:40" json:"deviceAdverstisingId"`
	DeviceMobileCarrier string    `sql:"size:40" json:"deviceMobileCarrier"`
	AppVersion          string    `sql:"size:40" json:"appVersion"`
	AppVersionCode      string    `sql:"size:40" json:"appVersionCode"`
	CreatedAt           time.Time `json:"createdAt"`
	UpdatedAt           time.Time `json:"updatedAt"`
	DeletedAt           time.Time `json:"-"`
}<commit_msg>pointers<commit_after>package main

import (
	"github.com/ant0ine/go-json-rest/rest"
	"github.com/jinzhu/gorm"
	_ "github.com/lib/pq"
	"github.com/yvasiyarov/go-metrics"
	"github.com/yvasiyarov/gorelic"
	"log"
	"net/http"
	"os"
	"time"
)

func main() {
	i := Impl{}
	i.InitDB()
	i.InitSchema()

	api := rest.NewApi()
	api.Use(rest.DefaultDevStack...)
	api.Use(&NewRelicMiddleware{
		License: os.Getenv("NEWRELIC_LICENCE_KEY"),
		Name:    "Puffin Event API",
		Verbose: true,
	})
	//api.Use(&rest.AccessLogJsonMiddleware{})
	router, err := rest.MakeRouter(
		rest.Post("/events", i.PostEvent),
		rest.Post("/installations", i.PostInstallation),
	)
	if err != nil {
		log.Fatal(err)
	}
	api.SetApp(router)
	log.Fatal(http.ListenAndServe("0.0.0.0:"+os.Getenv("PORT"), api.MakeHandler()))
}

type NewRelicMiddleware struct {
	License string
	Name    string
	Verbose bool
	agent   *gorelic.Agent
}

func (mw *NewRelicMiddleware) MiddlewareFunc(handler rest.HandlerFunc) rest.HandlerFunc {

	mw.agent = gorelic.NewAgent()
	mw.agent.NewrelicLicense = mw.License
	mw.agent.HTTPTimer = metrics.NewTimer()
	mw.agent.Verbose = mw.Verbose
	mw.agent.NewrelicName = mw.Name
	mw.agent.CollectHTTPStat = true
	mw.agent.Run()

	return func(writer rest.ResponseWriter, request *rest.Request) {

		handler(writer, request)

		// the timer middleware keeps track of the time
		startTime := request.Env["START_TIME"].(*time.Time)
		mw.agent.HTTPTimer.UpdateSince(*startTime)
	}
}

type Event struct {
	Id                          int64      `json:"id"`
	DeviceId                    string     `sql:"size:40" json:"deviceId"`
	MeasuredAt                  time.Time  `json:"measuredAt"`
	Measurement                 string     `sql:"size:1024" json:"measurement"`
	Value                       float64    `json:"value"`
	Fields                      string     `sql:"size:1024" json:"fields"`
	Tags                        string     `sql:"size:1024" json:"tags"`
	Note                        string     `sql:"size:1024" json:"note"`
	CreatedAt                   time.Time  `json:"createdAt"`
	UpdatedAt                   time.Time  `json:"updatedAt"`
	DeletedAt                   time.Time  `json:"-"`
	NotificationIntervalMinutes int64      `json:"notificationIntervalMinutes"`
	NotificationShownAt         *time.Time `json:"notificationShownAt"`
	NotificationDismissedAt     *time.Time `json:"notificationDismissedAt"`
	NotificationAcceptedAt      *time.Time `json:"notificationAcceptedAt"`
}

type Installation struct {
	Id                  int64     `json:"id"`
	DeviceType          string    `sql:"size:40" json:"deviceType"`
	DeviceManufacturer  string    `sql:"size:40" json:"deviceManufacturer"`
	DeviceModel         string    `sql:"size:40" json:"deviceModel"`
	DeviceProduct       string    `sql:"size:40" json:"deviceProduct"`
	DeviceSdk           string    `sql:"size:40" json:"deviceSdk"`
	DeviceSystemLocale  string    `sql:"size:40" json:"deviceSystemLocale"`
	DeviceAdvertisingId string    `sql:"size:40" json:"deviceAdverstisingId"`
	DeviceMobileCarrier string    `sql:"size:40" json:"deviceMobileCarrier"`
	AppVersion          string    `sql:"size:40" json:"appVersion"`
	AppVersionCode      string    `sql:"size:40" json:"appVersionCode"`
	CreatedAt           time.Time `json:"createdAt"`
	UpdatedAt           time.Time `json:"updatedAt"`
	DeletedAt           time.Time `json:"-"`
}
{'fraction_non_alphanumeric': 0.1333432215959656, 'fraction_numerical': 0.015129041827350934, 'mean_word_length': 3.0792498487598308, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '990037', 'n_tokens_mistral': 2319, 'n_tokens_neox': 2203, 'n_words': 402}