Documentation
¶
Index ¶
- Constants
- func AssetExpirationWorker(c *gin.Context)
- func CreateGeoLocation(ctx context.Context, ip string) error
- func ExpireAssets(ctx context.Context, ts int64) (int, error)
- func GetAssets(ctx context.Context, owner string, count, page int) *datastore.Iterator
- func LogRedirectRequest(ctx context.Context, asset *Asset, c *gin.Context) error
- type Asset
- type AssetRequest
- type AssetResponse
- type GeoLocation
- type LocationType
- type LookupResult
- type RedirectHistory
- type ResultsType
Constants ¶
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" )
const ( // DatastoreGeoLocation collection GEO_LOCATION DatastoreGeoLocation string = "GEOLOCATION" )
Variables ¶
This section is empty.
Functions ¶
func AssetExpirationWorker ¶
AssetExpirationWorker receives worker tasks to expire asset
func CreateGeoLocation ¶
CreateGeoLocation looks up the IP's geolocation if it is unknown
func ExpireAssets ¶
ExpireAssets looks for expired assets and changes their state
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
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