tracking

package module
v0.0.0-...-3b608a6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 2, 2023 License: MIT Imports: 20 Imported by: 0

README

tracking

Build Status | codecov | Go Report Card | GoDoc

A simple tracking and counting tool for site events. This is to be used for auditing.

Support for

Http

If i miss something or you have something interesting, please be part of this project. Let me know! My contact is at the end.

Dependecy Management

Dep

Project dependencies are managed using Dep. Read more about Dep.

  • Install dependencies: dep ensure
  • Update dependencies: dep ensure -update

Save tracking

Saving location by street

Method: POST Route: http://localhost:8001/api/v1/tracking/event Body:

{
	"category": "category",
	"action": "action",
	"label": "label",
	"value": 1,
	"viewer": "joao",
    "viewed": "jessica",
	"street": "rua particular de monsanto",
	"meta_data": {
		"teste_1": "teste",
		"teste_2": 1,
		"teste_3": 1.1
	}
}

Saving location by latitude, longitude

Method: POST Route: http://localhost:8001/api/v1/tracking/event Body:

{
	"category": "category",
	"action": "action",
	"label": "label",
	"value": 1,
	"viewer": "joao",
    "viewed": "jessica",
	"latitude": 41.1718238,
	"longitude": -8.6186277,
	"meta_data": {
		"teste_1": "teste",
		"teste_2": 1,
		"teste_3": 1.1
	}
}
Go
go get github.com/joaosoft/tracking

Usage

This examples are available in the project at tracking/examples

func main() {
	m, err := tracking.NewTracking()
	if err != nil {
		panic(err)
	}

	if err := m.Start(); err != nil {
		panic(err)
	}
}

Known issues

Follow me at

Facebook: https://www.facebook.com/joaosoft

LinkedIn: https://www.linkedin.com/in/jo%C3%A3o-ribeiro-b2775438/

If you have something to add, please let me know joaosoft@gmail.com

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrorNotFound = errors.New(errors.ErrorLevel, int(web.StatusNotFound), "not found")
)

Functions

This section is empty.

Types

type Action

type Action struct {
	IdAction  string    `json:"id_action" db:"id_action"`
	Name      string    `json:"name" db:"name"`
	CreatedAt time.Time `json:"created_at" db.read:"created_at" db.write:"-"`
}

type AddEventRequest

type AddEventRequest struct {
	Category  *string          `json:"category" validate:"notzero"`
	Action    *string          `json:"action" validate:"notzero"`
	Label     *string          `json:"label"`
	Value     *int64           `json:"value"`
	Viewer    *string          `json:"viewer"`
	Viewed    *string          `json:"viewed"`
	Latitude  *float64         `json:"latitude"`
	Longitude *float64         `json:"longitude"`
	Street    *string          `json:"street"`
	MetaData  *json.RawMessage `json:"meta_data"`
}

type AddEventResponse

type AddEventResponse struct {
	Success bool `json:"success"`
}

type AppConfig

type AppConfig struct {
	Tracking *TrackingConfig `json:"tracking"`
}

AppConfig ...

func NewConfig

func NewConfig() (*AppConfig, manager.IConfig, error)

newConfig ...

type Category

type Category struct {
	IdCategory string    `json:"id_category" db:"id_category"`
	Name       string    `json:"name" db:"name"`
	CreatedAt  time.Time `json:"created_at" db.read:"created_at" db.write:"-"`
}

type Controller

type Controller struct {
	// contains filtered or unexported fields
}

func NewController

func NewController(config *TrackingConfig, interactor *Interactor) *Controller

func (*Controller) AddEventHandler

func (c *Controller) AddEventHandler(ctx *web.Context) error

func (*Controller) RegisterRoutes

func (c *Controller) RegisterRoutes(web manager.IWeb) error

type ErrorResponse

type ErrorResponse struct {
	Code    web.Status `json:"code,omitempty"`
	Message string     `json:"message,omitempty"`
	Cause   string     `json:"cause,omitempty"`
}

type Event

type Event struct {
	IdEvent    string    `json:"id_event" db:"id_event"`
	Category   string    `json:"category" db:"-" validate:"notzero"`
	FkCategory string    `json:"-" db:"fk_category"`
	Action     string    `json:"action" db:"-" validate:"notzero"`
	FkAction   string    `json:"-" db:"fk_action"`
	Label      *string   `json:"label" db:"label"`
	Value      *int64    `json:"value" db:"value"`
	Viewer     *string   `json:"viewer" db:"viewer"`
	Viewed     *string   `json:"viewed" db:"viewed"`
	Latitude   *float64  `json:"latitude" db:"latitude"`
	Longitude  *float64  `json:"longitude" db:"longitude"`
	Country    *string   `json:"country" db:"country"`
	City       *string   `json:"city" db:"city"`
	Street     *string   `json:"street" db:"street"`
	MetaData   *string   `json:"meta_data" db:"meta_data"`
	CreatedAt  time.Time `json:"created_at" db.read:"created_at" db.write:"-"`
}

type IStorageDB

type IStorageDB interface {
	AddEvent(event *Event) error
}

type Interactor

type Interactor struct {
	// contains filtered or unexported fields
}

func NewInteractor

func NewInteractor(service *Tracking, storageDB IStorageDB, geoLocation *geolocation.GeoLocation) *Interactor

func (*Interactor) AddEvent

func (i *Interactor) AddEvent(event *Event) (*AddEventResponse, error)

type StoragePostgres

type StoragePostgres struct {
	// contains filtered or unexported fields
}

func NewStoragePostgres

func NewStoragePostgres(config *TrackingConfig) (*StoragePostgres, error)

func (*StoragePostgres) AddAction

func (storage *StoragePostgres) AddAction(action *Action) error

func (*StoragePostgres) AddCategory

func (storage *StoragePostgres) AddCategory(category *Category) error

func (*StoragePostgres) AddEvent

func (storage *StoragePostgres) AddEvent(event *Event) error

func (*StoragePostgres) GetActionByName

func (storage *StoragePostgres) GetActionByName(name string) (exists bool, action *Action, err error)

func (*StoragePostgres) GetCategoryByName

func (storage *StoragePostgres) GetCategoryByName(name string) (exists bool, category *Category, err error)

func (*StoragePostgres) UpsertCategoryActionAssociation

func (storage *StoragePostgres) UpsertCategoryActionAssociation(category *Category, action *Action) error

type Tracking

type Tracking struct {
	// contains filtered or unexported fields
}

func NewTracking

func NewTracking(options ...TrackingOption) (*Tracking, error)

NewTracking ...

func (*Tracking) Reconfigure

func (t *Tracking) Reconfigure(options ...TrackingOption)

Reconfigure ...

func (*Tracking) Start

func (t *Tracking) Start() error

Start ...

func (*Tracking) Stop

func (t *Tracking) Stop() error

Stop ...

type TrackingConfig

type TrackingConfig struct {
	Host              string                         `json:"host"`
	Dbr               *dbr.DbrConfig                 `json:"dbr"`
	TokenKey          string                         `json:"token_key"`
	ExpirationMinutes int64                          `json:"expiration_minutes"`
	Migration         *migration.MigrationConfig     `json:"migration"`
	GeoLocation       *geolocation.GeoLocationConfig `json:"geo-location"`
	Log               struct {
		Level string `json:"level"`
	} `json:"log"`
}

TrackingConfig ...

type TrackingOption

type TrackingOption func(t *Tracking)

TrackingOption ...

func WithConfiguration

func WithConfiguration(config *TrackingConfig) TrackingOption

WithConfiguration ...

func WithLogLevel

func WithLogLevel(level logger.Level) TrackingOption

WithLogLevel ...

func WithLogger

func WithLogger(logger logger.ILogger) TrackingOption

WithLogger ...

func WithManager

func WithManager(mgr *manager.Manager) TrackingOption

WithManager ...

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL