Documentation ¶
Overview ¶
Package data is the package for dealing with the data layer of townsourced. This means the following:
RethinkDB Memcache Elasticsearch
NOTE: For Rethinkdb, be very careful when using maps in structs, as updates won't remove fields in maps
You'll need to due a full replace instead. Generally it's safer, and more performant to use a slice instead
Index ¶
- Constants
- Variables
- func AdminLastPosts(result interface{}) error
- func AdminLastTowns(result interface{}) error
- func AdminLastUsers(result interface{}) error
- func AdminPostCountTrend(result interface{}, since time.Time) error
- func AdminTownCountTrend(result interface{}, since time.Time) error
- func AdminUserCountTrend(result interface{}, since time.Time) error
- func AttemptsGet(result interface{}, id, requestType string) error
- func AttemptsSet(attempts interface{}, id, requestType string, timeRange time.Duration) error
- func CacheClient() *memcache.Client
- func CommentGet(result interface{}, key UUID) error
- func CommentGetTree(result interface{}, key UUID, limit int, sort string) error
- func CommentUpdate(comment interface{}, key UUID) error
- func CommentsGet(result interface{}, postKey, parent UUID, from, limit int, sort string) (err error)
- func CommentsGetByUser(result interface{}, username Key, public bool, since time.Time, limit int) (err error)
- func DatabaseSession() *rt.Session
- func FromUUID(g UUID) string
- func IP2LocationGet(result interface{}, ipAddress string) error
- func IP2LocationImport(entries interface{}) error
- func IP2LocationTruncate() error
- func IPNumber(address string) uint64
- func ImageDelete(key UUID) error
- func ImageDeleteOrphans(updatedSince time.Time) error
- func ImageGet(result interface{}, key UUID, thumb, placeholder bool) error
- func ImageUpdate(image interface{}, key UUID) error
- func Init(cfg *Config) error
- func Log(entry interface{}) error
- func NotificationGet(result interface{}, notificationKey UUID) error
- func NotificationGetAll(result interface{}, username Key, since time.Time, limit int) error
- func NotificationGetUnread(result interface{}, username Key, since time.Time, limit int) error
- func NotificationInsert(notification interface{}) error
- func NotificationUnreadCount(username Key) (int, error)
- func NotificationUpdate(notification interface{}, key UUID) error
- func NotificationUpdateUnread(notification interface{}, username Key) error
- func NotificationsGetSent(result interface{}, username Key, since time.Time, limit int) (err error)
- func PostAllCount() (int, error)
- func PostGet(result interface{}, key UUID) error
- func PostGetAll(result interface{}, from, limit int) error
- func PostGetByTowns(result interface{}, towns []Key, category string, since time.Time, limit int, ...) (err error)
- func PostGetByUser(result interface{}, username Key, status string, public bool, since time.Time, ...) (err error)
- func PostGetUserSaved(result interface{}, username Key, status string, from, limit int) (err error)
- func PostIndex(post interface{}, key UUID) error
- func PostRemoveIndex(key UUID) error
- func PostUpdate(post interface{}, key UUID) error
- func SearchClient() *elastic.Client
- func SessionGet(result interface{}, sessionKey string) error
- func SessionInsert(s interface{}, sessionKey string, expires time.Time) error
- func SessionUpdate(s interface{}, sessionKey string, expires time.Time) error
- func TaskClaim(owner Key, limit uint) error
- func TaskDeleteClosed() error
- func TaskGetMine(result interface{}, owner Key) (err error)
- func TaskGetOpenType(result interface{}, taskType string, limit uint) (err error)
- func TaskInsert(task interface{}) error
- func TaskUpdate(task interface{}, key UUID) error
- func TempTokenExpire(token string) error
- func TempTokenGet(tokenData interface{}, token string) error
- func TempTokenSet(tokenData interface{}, token string, expires time.Duration) error
- func TownAllCount() (int, error)
- func TownGet(result interface{}, key Key) error
- func TownGetAll(result interface{}, from, limit int) error
- func TownGetByLocation(result interface{}, locationQry LocationSearcher, from, limit int) error
- func TownGetPopulation(key Key) (int, error)
- func TownIndex(town interface{}, key Key) error
- func TownInsert(data interface{}, key Key) error
- func TownRemoveIndex(key Key) error
- func TownUpdate(data interface{}, key Key) error
- func Towns(result interface{}, keys ...Key) (err error)
- func UserAllCount() (int, error)
- func UserGet(result interface{}, username Key) error
- func UserGetEmail(result interface{}, email string) error
- func UserGetFacebook(result interface{}, facebookID string) error
- func UserGetGoogle(result interface{}, googleID string) error
- func UserGetMatching(result interface{}, match string, limit int) error
- func UserGetTwitter(result interface{}, twitterID string) error
- func UserInsert(user interface{}) error
- func UserUpdate(user interface{}, username Key) error
- type AreaSearch
- type CacheConfig
- type Config
- type DBConfig
- type DistanceSearch
- type Key
- type KeyWhen
- type KeyWhenSlice
- type LatLng
- type LocationSearcher
- type SearchConfig
- type SearchIndexConfig
- type SearchResult
- type UUID
- type UUIDWhen
- type UUIDWhenSlice
- type Version
Constants ¶
const ( CommentSortNew = "new" CommentSortOld = "old" )
CommentSort sets the sort order on comments
const ( LocationUnitMeter = "m" LocationUnitKilometer = "km" LocationUnitMile = "mi" LocationUnitNauticalMile = "nm" LocationUnitFoot = "ft" )
LocationUnit defines units of measure for location based queries
const ( // PostStatusDraft not public visible yet PostStatusDraft = "draft" // PostStatusPublished publicly visible PostStatusPublished = "published" //PostStatusClosed not searchable but link is still valid PostStatusClosed = "closed" )
const ( PostSearchSortNone = "" PostSearchPriceSortHighToLow = "pricehigh" PostSearchPriceSortLowToHigh = "pricelow" PostSearchSortNew = "new" PostSearchSortOld = "old" )
PostSort sets the sort order on post search results
const AnnouncementTown = "announcements"
AnnouncementTown is the key of the townsourced announcements town
const CommentMaxDepth = 7
CommentMaxDepth is the max depth at which to retrieve nested comment children
const DatabaseName = "townsourced"
DatabaseName is the name of the townsourced database
const EmptyKey = Key("")
EmptyKey is an empty key value
const EmptyUUID = UUID("")
EmptyUUID is an empty UUID value
const MaxKeyLength = 127
MaxKeyLength is the longest possible Key
Variables ¶
var ErrNotFound = errors.New("Data not found")
ErrNotFound is the error returned when no records are found for the given criteria
var ErrVersionStale = &fail.Fail{ Message: "You are trying to update this record based on old information. " + "Please refresh your screen and try again.", HTTPStatus: http.StatusConflict, }
ErrVersionStale is when an update is attempted with a version older than the current version in the database
Functions ¶
func AdminLastPosts ¶
func AdminLastPosts(result interface{}) error
AdminLastPosts returns the last 3 posts published
func AdminLastTowns ¶
func AdminLastTowns(result interface{}) error
AdminLastTowns returns the last 3 towns registered
func AdminLastUsers ¶
func AdminLastUsers(result interface{}) error
AdminLastUsers returns the last 3 users who signed up
func AdminPostCountTrend ¶
AdminPostCountTrend gets the trend in post counts by day
func AdminTownCountTrend ¶
AdminTownCountTrend gets the trend in town counts by day
func AdminUserCountTrend ¶
AdminUserCountTrend gets the trend in user counts by day
func AttemptsGet ¶
AttemptsGet gets all previous attempts for the given ipaddress+type
func AttemptsSet ¶
AttemptsSet sets the current attemps for the given ipaddress / type
func CacheClient ¶
CacheClient returns the underlying memcached client should usually only be used in tools and tests
func CommentGet ¶
CommentGet retrieves a single comment
func CommentGetTree ¶
CommentGetTree retrieves a single comment and it's children
func CommentUpdate ¶
CommentUpdate updates an existing comment
func CommentsGet ¶
func CommentsGet(result interface{}, postKey, parent UUID, from, limit int, sort string) (err error)
CommentsGet retrieves a set of comments
func CommentsGetByUser ¶
func CommentsGetByUser(result interface{}, username Key, public bool, since time.Time, limit int) (err error)
CommentsGetByUser retrieves a set of comments posted by a given user
func DatabaseSession ¶
DatabaseSession returns the underlying rethinkdb database session should usually only be used in tools and tests
func IP2LocationGet ¶
IP2LocationGet retrieves a LatLng location from the passed in IPAddress
func IP2LocationImport ¶
func IP2LocationImport(entries interface{}) error
IP2LocationImport imports an array for IP2Location entries
func IP2LocationTruncate ¶
func IP2LocationTruncate() error
IP2LocationTruncate truncates the IP2Location table by dropping it and recreating it. Much faster than deleting all the records individually
func ImageDeleteOrphans ¶
ImageDeleteOrphans deletes all images that aren't currently in use and haven't been updated since the passed in time
func ImageUpdate ¶
ImageUpdate updates an existing image
func NotificationGet ¶
NotificationGet retrieves a specific notification for a user
func NotificationGetAll ¶
NotificationGetAll retrieves all notifications for a user
func NotificationGetUnread ¶
NotificationGetUnread retrieves all unread notifications for a user
func NotificationInsert ¶
func NotificationInsert(notification interface{}) error
NotificationInsert inserts a new user notification into the database
func NotificationUnreadCount ¶
NotificationUnreadCount retrieves the number of unread notifications for a user
func NotificationUpdate ¶
NotificationUpdate updates a single notification
func NotificationUpdateUnread ¶
NotificationUpdateUnread updates all unread notifications
func NotificationsGetSent ¶
NotificationsGetSent gets all sent notifications for a user
func PostAllCount ¶
PostAllCount returns the count of the total number of posts, usually used by maintenance and not the frontend
func PostGetAll ¶
PostGetAll retrieves all posts This likely shouldn't be used for the actual website, and should only be used for maintenance / tasks
func PostGetByTowns ¶
func PostGetByTowns(result interface{}, towns []Key, category string, since time.Time, limit int, showModerated bool) (err error)
PostGetByTowns retrieves posts by the passed in list of townkeys
func PostGetByUser ¶
func PostGetByUser(result interface{}, username Key, status string, public bool, since time.Time, limit int) (err error)
PostGetByUser retrieves posts by a specific user
func PostGetUserSaved ¶
PostGetUserSaved retrieves posts saved by a specific user in the order in which they were saved
func PostRemoveIndex ¶
PostRemoveIndex removes the given post from the full text search index
func PostUpdate ¶
PostUpdate updates an existing post
func SearchClient ¶
SearchClient returns the underlying elasticSearch client should usually only be used in tools and tests
func SessionGet ¶
SessionGet retrieves a session
func SessionInsert ¶
SessionInsert inserts a session
func SessionUpdate ¶
SessionUpdate updates a session
func TaskClaim ¶
TaskClaim marks the next set of unclaimed, non-closed tasks as owned by the given user this is to immediately prevent any other task runners from sharing these tasks A task should only belong to one runner at a time
func TaskGetMine ¶
TaskGetMine retrieves all unprocessed tasks that have been marked as the owenres, who's nextRun time has passed in order by priority, then oldest tasks
func TaskGetOpenType ¶
TaskGetOpenType gets all open tasks of a given type
func TaskUpdate ¶
TaskUpdate updates a single task
func TempTokenExpire ¶
TempTokenExpire will expire the temp token with the passed in ID
func TempTokenGet ¶
TempTokenGet gets a tempory token
func TempTokenSet ¶
TempTokenSet sets a session in the memcache if expires is less than 30 minutes, otherwise it goes in rethink
func TownAllCount ¶
TownAllCount returns the count of the total number of towns, usually used by maintenance and not the frontend
func TownGetAll ¶
TownGetAll retrieves all towns This likely shouldn't be used for the actual website, and should only be used for maintenance / tasks
func TownGetByLocation ¶
func TownGetByLocation(result interface{}, locationQry LocationSearcher, from, limit int) error
TownGetByLocation retrieves all towns within the distance passed from the location passed in
func TownGetPopulation ¶
TownGetPopulation retrieves the current population of a town
func TownRemoveIndex ¶
TownRemoveIndex removes the given town from the full text search indexes
func UserAllCount ¶
UserAllCount returns the count of the total number of users
func UserGetEmail ¶
UserGetEmail gets a user with an email address
func UserGetFacebook ¶
UserGetFacebook gets a user with their FacebookID
func UserGetGoogle ¶
UserGetGoogle gets a user with their GoogleID
func UserGetMatching ¶
UserGetMatching retrieves all users who's username starts with the passed in string
func UserGetTwitter ¶
UserGetTwitter gets a user with their TwitterID
func UserInsert ¶
func UserInsert(user interface{}) error
UserInsert inserts a new user into the database
func UserUpdate ¶
UserUpdate updates an existing user
Types ¶
type AreaSearch ¶
type AreaSearch struct {
// contains filtered or unexported fields
}
AreaSearch is a location search for everything withing a rectangle area
func NewAreaSearch ¶
func NewAreaSearch(northBounds, southBounds, eastBounds, westBounds float64) (*AreaSearch, error)
NewAreaSearch returns a new area search query
type CacheConfig ¶
type CacheConfig struct {
Addresses []string `json:"addresses,omitempty"`
}
CacheConfig is cache server connection configuration
type Config ¶
type Config struct { DB DBConfig `json:"db"` Cache CacheConfig `json:"cache"` Search SearchConfig `json:"search"` DevMode bool `json:"-"` }
Config is data layer configuration thinks like database ip addresses, cache servers, etc
func DefaultConfig ¶
func DefaultConfig() *Config
DefaultConfig returns the default configuration for the data layer
type DBConfig ¶
type DBConfig struct { Address string `json:"address,omitempty"` Addresses []string `json:"addresses,omitempty"` Database string `json:"database,omitempty"` AuthKey string `json:"authkey,omitempty"` Timeout string `json:"timeout,omitempty"` TLSConfig *tls.Config `json:"tlsconfig,omitempty"` MaxIdle int `json:"max_idle,omitempty"` MaxOpen int `json:"max_open,omitempty"` // DiscoverHosts is used to enable host discovery, when true the driver // will attempt to discover any new nodes added to the cluster and then // start sending queries to these new nodes. DiscoverHosts bool `json:"discoverHosts,omitempty"` // NodeRefreshInterval is used to determine how often the driver should // refresh the status of a node. NodeRefreshInterval time.Duration `json:"nodeRefreshInterval,omitempty"` // contains filtered or unexported fields }
DBConfig is database config
type DistanceSearch ¶
type DistanceSearch struct {
// contains filtered or unexported fields
}
DistanceSearch is a location search based on distance from a single point
func NewDistanceSearch ¶
func NewDistanceSearch(latLng LatLng, maxDistance float64, unit string) *DistanceSearch
NewDistanceSearch creates a new distance search type
type Key ¶
type Key string
Key is a unique identifier for a given peice of data
Key handling rules are as follows Never use data.Key(value), use data.NewKey(value) Web layer code deals with strings, app layer code deals with keys the transfer from Web to App will make sure keys are properly cased
func NewKey ¶
NewKey returns a new Key from the passed in string use this instead of data.Key(key) to make new keys to ensure that it's properly lowercase
func NewKeySlice ¶
NewKeySlice is a help for building a slice of keys from strings
func (*Key) UnmarshalJSON ¶
UnmarshalJSON implments a custom JSON unmarshaller for reading a Key from JSON input, to ensure all keys coming from user input via JSON are properly lower case
type KeyWhen ¶
KeyWhen is a helper for the serveral instances where you want to keep track of a list of joining keys as well as when those keys where added joining a town saved posts, etc
type KeyWhenSlice ¶
type KeyWhenSlice []KeyWhen
KeyWhenSlice is a slice of KeyWhens
func (KeyWhenSlice) Keys ¶
func (k KeyWhenSlice) Keys() []Key
Keys gets a list of keys form a KeyWhen slice
type LocationSearcher ¶
type LocationSearcher interface {
// contains filtered or unexported methods
}
LocationSearcher is an interface for searching based on location
type SearchConfig ¶
type SearchConfig struct { Addresses []string `json:"addresses,omitempty"` MaxRetries int `json:"maxRetries,omitEmpty"` Index SearchIndexConfig `json:"index,omitempty"` }
SearchConfig is search server connection configuration
type SearchIndexConfig ¶
type SearchIndexConfig struct { Name string `json:"name,omitempty"` Shards int `json:"shards,omitempty"` Replicas int `json:"replicas,omitempty"` }
SearchIndexConfig is config for how the main elasticSearch index should be configure
type SearchResult ¶
type SearchResult struct {
// contains filtered or unexported fields
}
SearchResult is the result values of a search
used for Deserializing data from the results of a search
TODO: Highlight results? TODO: Search Suggestions
func PostSearch ¶
func PostSearch(searchText string, tags []string, towns []Key, category string, from, limit int, postSort string, minPrice, maxPrice float64, showModerated bool) (*SearchResult, error)
PostSearch retrieves posts in relevant order by the search text or tags, for the given towns use PostSort* enumeration for sorting
func TownGetBySearch ¶
func TownGetBySearch(search string, from, limit int) (*SearchResult, error)
TownGetBySearch retrieves a list of towns based on a full text search of the town's name and description
func (*SearchResult) Count ¶
func (r *SearchResult) Count() int
Count returns the number of search results
func (*SearchResult) Next ¶
func (r *SearchResult) Next(result interface{}) error
Next fetches the next value from the search result returns io.EOF when there are no more items example:
posts = make([]Post, result.Count()) for i := range posts { err = result.Next(&posts[i]) if err != nil { return nil, err } }
type UUID ¶
type UUID string
A UUID is like a key (a unique identifier), but it is machine generated rather than user generated and it is shortened for user facing urls and json data
func CommentInsert ¶
CommentInsert inserts a new user notification into the database
func ImageInsert ¶
ImageInsert inserts a new image into the database
func NewUUID ¶
func NewUUID() UUID
NewUUID returns a new generated UUID this should rarely be used, and the database should mostly be responsible for generating new UUIDs
func PostInsert ¶
PostInsert inserts a new post into the database
func ToUUID ¶
ToUUID takes a Base64 encoded string and converts it to a full UUID if it can't be decoded then an empty UUID is returned
func (*UUID) MarshalJSON ¶
MarshalJSON implements a custom JSON marshaler for a UUID to shorten the UUID via base64 for more readable URLs
func (*UUID) UnmarshalJSON ¶
UnmarshalJSON implments a custom JSON unmarshaller for reading the base64 encoded value that the UUID was written to
type UUIDWhen ¶
UUIDWhen is a helper for the serveral instances where you want to keep track of a list of joining UUIDS as well as when those guids where added saved posts, etc
type UUIDWhenSlice ¶
type UUIDWhenSlice []UUIDWhen
UUIDWhenSlice is a slice of UUIDWhens
func (UUIDWhenSlice) UUIDs ¶
func (g UUIDWhenSlice) UUIDs() []UUID
UUIDs gets a list of guids form a UUIDWhen slice
type Version ¶
type Version struct { VerTag string `json:"vertag,omitempty" gorethink:",omitempty"` Created time.Time `json:"created,omitempty" gorethink:",omitempty"` Updated time.Time `json:"updated,omitempty" gorethink:",omitempty"` }
Version is meant to be used as an anonymous struct to gain built in version protection on updates, and track created an updated dates
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package private is for private items like passwords, API keys, and anything else that shouldn't be released to a public repository *when* townsourced is opensourced.
|
Package private is for private items like passwords, API keys, and anything else that shouldn't be released to a public repository *when* townsourced is opensourced. |
tools
|
|