db

package
v0.0.0-...-a8af6b5 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2020 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DayFormat = "2006-01-02"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Database

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

func Init

func Init(storagePath string) *Database

func (Database) Close

func (d Database) Close()

func (Database) DeleteShortURLandStats

func (d Database) DeleteShortURLandStats(ID int) error

func (Database) GetAll

func (d Database) GetAll() ([]ShortURL, error)

func (Database) GetAllMapped

func (d Database) GetAllMapped() (map[string]ShortURL, error)

func (Database) GetAllStatisticsGroupedByURLs

func (d Database) GetAllStatisticsGroupedByURLs() (map[string]OneURLSummaryStatistics, error)

func (Database) GetStatisticForOneURLOneDay

func (d Database) GetStatisticForOneURLOneDay(shortUrlID int, dayDate time.Time) (*ShortURL, []OneViewStatistic, error)

func (Database) GetStatisticsForOneURL

func (d Database) GetStatisticsForOneURL(shortUrlID int) (*ShortURL, map[string]OneDaySummaryStatistics, error)

func (Database) GetUrl

func (d Database) GetUrl(suffix string) (*ShortURL, error)

func (Database) GetUrlByID

func (d Database) GetUrlByID(ID int) (*ShortURL, error)

func (Database) GetViewByID

func (d Database) GetViewByID(ID int) (*OneViewStatistic, error)

func (Database) IsEmpty

func (d Database) IsEmpty() bool

func (Database) SaveShortUrl

func (d Database) SaveShortUrl(shortSuffix, fullTargetAddress, description string, isPublic bool) error

func (Database) SaveShortUrlObject

func (d Database) SaveShortUrlObject(shortUrl *ShortURL) error

func (Database) SaveStatisticForOneView

func (d Database) SaveStatisticForOneView(ipAddress, requestedUrl, countryCode, countryName, city, userAgent string) error

func (Database) UpdateShortUrl

func (d Database) UpdateShortUrl(id, fieldName string, value interface{}) error

type OneDaySummaryStatistics

type OneDaySummaryStatistics struct {
	Date               string // format is 2006-01-02
	DateWithoutHyphens string // format is 20060102
	TotalViews         int
	UniqueViews        int
}

type OneURLSummaryStatistics

type OneURLSummaryStatistics struct {
	ID               int
	ShortUrlID       int
	ShortUrl         string
	PublishDate      string // format is 2006-01-02
	TotalDaysActive  int
	TotalViews       int
	TotalUniqueUsers int
}

representation only

type OneViewStatistic

type OneViewStatistic struct {
	ID            int    `storm:"id,increment"`
	UserIpAddress string `storm:"index"`
	ShortUrl      string `storm:"index"` // shortened URL suffix
	Day           string `storm:"index"` // just a date sortable in format of 2020-01-02, to be able to select all the views for a day
	CountryCode   string
	CountryName   string
	City          string
	UserAgent     string
	ViewTimes     []time.Time // one view is one time record, UTC
}

type ShortURL

type ShortURL struct {
	ID          int    `storm:"id,increment"`
	ShortUrl    string `storm:"unique"` // unique primary key
	TargetUrl   string
	Description string
	IsPublic    bool
	PublishDate string // format is 2006-01-02
}

Jump to

Keyboard shortcuts

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