shortener

package
v0.0.0-...-182577b Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2020 License: AGPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DatastoreAssets collection ASSETS
	DatastoreAssets string = "ASSETS"
	// DatastoreRedirectHistory collection MEASUREMENT
	DatastoreRedirectHistory string = "REDIRECT_HISTORY"

	// StateActive and the other states decribe thr assets lifecycle
	StateActive = iota
	// StateArchived = the asset was disabled by its owner
	StateArchived
	// StateExpired = the asset was not activated for x days
	StateExpired
	// StateBroken = the asset's target does not exist
	StateBroken

	// LastAccessThreshold is the time we allow to pass before updating the LastAccess attribute, again
	LastAccessThreshold = 3600 * 6 // 6h
	// ExpireAfter defines the age of an asset before it expires (in seconds).
	ExpireAfter int64 = 30 // days

	// DailyExpiration is a metric to track how many assets were expired
	DailyExpiration = "DAILY_EXPIRATION"
)
View Source
const (
	// DatastoreGeoLocation collection GEO_LOCATION
	DatastoreGeoLocation string = "GEOLOCATION"
)

Variables

This section is empty.

Functions

func AssetExpirationWorker

func AssetExpirationWorker(c *gin.Context)

AssetExpirationWorker receives worker tasks to expire asset

func CreateGeoLocation

func CreateGeoLocation(ctx context.Context, ip string) error

CreateGeoLocation looks up the IP's geolocation if it is unknown

func ExpireAssets

func ExpireAssets(ctx context.Context, ts int64) (int, error)

ExpireAssets looks for expired assets and changes their state

func GetAssets

func GetAssets(ctx context.Context, owner string, count, page int) *datastore.Iterator

GetAssets returns an array of count assets for owner, starting at page

func LogRedirectRequest

func LogRedirectRequest(ctx context.Context, asset *Asset, c *gin.Context) error

LogRedirectRequest creates the analytics data for a redirect request

Types

type Asset

type Asset struct {
	LongLink    string `json:"long_link" binding:"required"`
	ShortLink   string `json:"short_link" binding:"required"`
	PreviewLink string `json:"preview_link,omitempty"`
	// ownership etc
	Owner       string `json:"owner,omitempty"`
	AccessToken string `json:"token,omitempty"`
	// metadata
	Tags        string `json:"tags,omitempty"`
	ParentID    string `json:"parent,omitempty"`
	Title       string `json:"title,omitempty"`
	Description string `json:"description,omitempty"`
	// status
	State      int   `json:"state,omitempty"`
	LastAccess int64 `json:"last_access"`

	// segmentation
	Source string `json:"source,omitempty"`

	// internal
	Created  int64 `json:"created"`
	Modified int64 `json:"modified"`
}

Asset is the interal datastore structure used to store assets

func GetURL

func GetURL(ctx context.Context, shortLink string, touch bool) (*Asset, error)

GetURL retrieves the asset

type AssetRequest

type AssetRequest struct {
	// Link is the long form URL
	Link string `json:"link" binding:"required"`
	// Owner identifies the owner of the asset
	Owner string `json:"owner" binding:"required"`
	// ParentID is the id of the category the asset belongs to
	ParentID string `json:"parent,omitempty"`
	// Source identiefies the client who created the request
	Source string `json:"source,omitempty"`
}

AssetRequest is the request body used to create a new asset

type AssetResponse

type AssetResponse struct {
	// Link is the long form URL
	Link string `json:"link" binding:"required"`
	// ShortLink is the ID or suffix
	ShortLink string `json:"short_link,omitempty"`
	// PreviewLink is not use for now. Defaults to the canonical short link for now
	PreviewLink string `json:"preview_link,omitempty"`
	// Owner identifies the owner of the asset
	Owner string `json:"owner" binding:"required"`
	// AccessToken is used as a 'Secret' in order to claim or access the asset
	AccessToken string `json:"token,omitempty"`
}

AssetResponse contains the relevant attributes after creating a new asset

func CreateURL

func CreateURL(ctx context.Context, as *AssetRequest) (*AssetResponse, error)

CreateURL creates a new asset

type GeoLocation

type GeoLocation struct {
	IP          string `json:"ip"`
	ISP         string `json:"isp"`
	City        string `json:"city"`
	CountryCode string `json:"country_code"`
	CountryName string `json:"country_name"`
	Latitude    string `json:"latitude"`
	Longitude   string `json:"longitude"`
}

GeoLocation records a IP's geo location

type LocationType

type LocationType struct {
	Text        string `xml:",chardata"`
	IP          string `xml:"ip"`
	Host        string `xml:"host"`
	Isp         string `xml:"isp"`
	City        string `xml:"city"`
	Countrycode string `xml:"countrycode"`
	Countryname string `xml:"countryname"`
	Latitude    string `xml:"latitude"`
	Longitude   string `xml:"longitude"`
}

LocationType holds the geo data

func LookupGeoLocation

func LookupGeoLocation(ip string) (*LocationType, error)

LookupGeoLocation looks up the IP's geolocation

type LookupResult

type LookupResult struct {
	XMLName xml.Name    `xml:"ip"`
	Text    string      `xml:",chardata"`
	Results ResultsType `xml:"results"`
}

LookupResult is the struct returned by a lookup on geoiplookup.net

type RedirectHistory

type RedirectHistory struct {
	ShortLink string `json:"short_link" binding:"required"`
	// requester metadata
	Requester string `json:"requester" binding:"required"`
	IP        string `json:"ip,omitempty"`
	Owner     string `json:"owner,omitempty"`
	// browser metadata
	UserAgent      string `json:"user_agent,omitempty"`
	AcceptLanguage string `json:"accept_language,omitempty"`
	// campaign metadata, see https://support.google.com/analytics/answer/1033863
	Source   string `json:"utm_source,omitempty"`
	Medium   string `json:"utm_medium,omitempty"`
	Campaign string `json:"utm_campaign,omitempty"`
	Content  string `json:"utm_content,omitempty"`
	// internal metadata
	Created int64 `json:"-"`
}

RedirectHistory records redirect events

type ResultsType

type ResultsType struct {
	XMLName xml.Name     `xml:"results"`
	Text    string       `xml:",chardata"`
	Result  LocationType `xml:"result"`
}

ResultsType container for the location

Jump to

Keyboard shortcuts

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