Documentation ¶
Overview ¶
Package helpers provides helper and utility functions that are shared by all parts of the Microcosm application
Index ¶
- Constants
- Variables
- func AttendanceStatus(query url.Values) (string, int, error)
- func Btoi(boolean bool) int
- func GetAttending(query url.Values) (bool, int, error)
- func GetConnection() (*sql.DB, error)
- func GetCurrentPage(offset int64, limit int64) int64
- func GetItemAndItemType(query url.Values) (int64, string, int, error)
- func GetItemTypeFromInt(value int64) (string, error)
- func GetLimitAndOffset(query url.Values) (int64, int64, int, error)
- func GetLinkToThisPage(requestURL url.URL, offset int64, limit int64, total int64) url.URL
- func GetMapStringFromInt(theMap map[string]int64, value int64) (string, error)
- func GetMaxOffset(total int64, limit int64) int64
- func GetPageCount(total int64, limit int64) int64
- func GetTransaction() (*sql.Tx, error)
- func InitDBConnection(c DBConfig)
- func IsValidColor(color string) bool
- func MD5Sum(s string) string
- func RandString(length int) (string, error)
- func SHA1(bytes []byte) (string, error)
- func TestPatch(patches []PatchType) (int, error)
- type ArrayType
- type AttachmentType
- type CoreMetaType
- type CreatedMetaType
- type CreatedType
- type DBConfig
- type DefaultMetaType
- type DefaultNoFlagsMetaType
- type DefaultReducedFlagsMetaType
- type EditedType
- type Er
- type ExtendedMetaType
- type FlagsType
- type LinkArrayType
- type LinkType
- type PatchType
- type SimpleFlagsType
- type SimpleMetaType
- type StatType
- type SummaryMetaType
- type ThumbnailType
Constants ¶
const ( ItemTypeActivity string = "activity" ItemTypeAlbum string = "album" ItemTypeArticle string = "article" ItemTypeAttendee string = "attendee" ItemTypeAttachment string = "attachment" ItemTypeAttribute string = "attribute" ItemTypeAuth string = "auth" ItemTypeClassified string = "classified" ItemTypeComment string = "comment" ItemTypeConversation string = "conversation" ItemTypeEvent string = "event" ItemTypeFile string = "file" ItemTypeHuddle string = "huddle" ItemTypeMicrocosm string = "microcosm" ItemTypePoll string = "poll" ItemTypeProfile string = "profile" ItemTypeQuestion string = "question" ItemTypeRole string = "role" ItemTypeSite string = "site" ItemTypeUpdate string = "update" ItemTypeUpdateOptionType string = "update_type" ItemTypeUser string = "user" ItemTypeWatcher string = "watcher" ItemTypeWhoAmI string = "whoami" )
Constants for all of the itemTypes
const ( APITypeActivity string = "/api/v1/activity" APITypeAlbum string = "/api/v1/albums" APITypeArticle string = "/api/v1/articles" APITypeAttendee string = "/api/v1/events/%d/attendees" APITypeAttachment string = "attachments" APITypeAttribute string = "/api/v1/%s/%d/attributes" APITypeAuth string = "/api/v1/auth" APITypeClassified string = "/api/v1/classifieds" APITypeComment string = "/api/v1/comments" APITypeConversation string = "/api/v1/conversations" APITypeEvent string = "/api/v1/events" APITypeFile string = "/api/v1/files" APITypeHuddle string = "/api/v1/huddles" APITypeMicrocosm string = "/api/v1/microcosms" APITypeQuestion string = "/api/v1/questions" APITypePoll string = "/api/v1/polls" APITypeProfile string = "/api/v1/profiles" APITypeRole string = "/api/v1/roles" APITypeSite string = "/api/v1/sites" APITypeUpdate string = "/api/v1/updates" APITypeUpdateOptionType string = "/api/v1/updates/preferences/%d" APITypeUser string = "/api/v1/users" APITypeWatcher string = "/api/v1/watchers" APITypeWhoAmI string = "/api/v1/whoami" )
List of APITypes
const ( UpdateTypeNewComment string = "new_comment" UpdateTypeReplyToComment string = "reply_to_comment" UpdateTypeMentioned string = "mentioned" UpdateTypeNewCommentInHuddle string = "new_comment_in_huddle" UpdateTypeNewEventAttendee string = "new_attendee" UpdateTypeNewPollVote string = "new_vote" UpdateTypeEventReminder string = "event_reminder" UpdateTypeNewItem string = "new_item" UpdateTypeNewUser string = "new_user" )
List of update_types
const ( UpdateTextNewComment string = "There is a new comment in an item you are subscribed to" UpdateTextReplyToComment string = "A user has replied to your post" UpdateTextMentioned string = "You were mentioned in a comment" UpdateTextNewCommentInHuddle string = "There is a new comment in a huddle that you are part of" UpdateTextNewEventAttendee string = "A user has RSVPed to an event you are subscribed to" UpdateTextNewPollVote string = "A vote has been cast in a poll you are subscribed to" UpdateTextEventReminder string = "You have an upcoming event" UpdateTextNewItem string = "There is a new item in a microcosm you are subscribed to" UpdateTextNewUser string = "There is a new user and you are watching all profiles" )
List of texts for update_types
const ( // DefaultQueryLimit defines the default number of items per page for APIs DefaultQueryLimit int64 = 25 // DefaultQueryOffset defines the default offset for API responses DefaultQueryOffset int64 = 0 )
const JumpURL string = "http://microcosm.app/out/"
JumpURL is the URL to use for external URL redirects
const NoAuthMessage = "You do not have permission to do that"
NoAuthMessage is the unauthorised error message
Variables ¶
var AllowedChars = []byte("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")
AllowedChars is the range of chars that can appear in a random string
var ItemTypes = map[string]int64{ ItemTypeSite: 1, ItemTypeMicrocosm: 2, ItemTypeProfile: 3, ItemTypeComment: 4, ItemTypeHuddle: 5, ItemTypeConversation: 6, ItemTypePoll: 7, ItemTypeArticle: 8, ItemTypeEvent: 9, ItemTypeQuestion: 10, ItemTypeClassified: 11, ItemTypeAlbum: 12, ItemTypeAttendee: 13, ItemTypeUser: 14, ItemTypeAttribute: 15, ItemTypeUpdate: 16, ItemTypeRole: 17, ItemTypeUpdateOptionType: 18, ItemTypeWatcher: 19, ItemTypeAuth: 20, ItemTypeAttachment: 21, }
ItemTypes is a list of all itemTypes
var ItemTypesCommentable = map[string]int64{ ItemTypeProfile: 3, ItemTypeHuddle: 5, ItemTypeConversation: 6, ItemTypePoll: 7, ItemTypeArticle: 8, ItemTypeEvent: 9, ItemTypeQuestion: 10, ItemTypeClassified: 11, ItemTypeAlbum: 12, }
ItemTypesCommentable is a list of the itemTypes that can have comments on them
var ItemTypesScoreable = map[string]int64{ ItemTypeConversation: 6, ItemTypePoll: 7, ItemTypeArticle: 8, ItemTypeEvent: 9, ItemTypeQuestion: 10, ItemTypeClassified: 11, ItemTypeAlbum: 12, }
ItemTypesScoreable is a list of the itemTypes that will be scored to determine trending items
var ItemTypesToAPIItem = map[string]string{ ItemTypeAttendee: APITypeAttendee, ItemTypeActivity: APITypeActivity, ItemTypeAlbum: APITypeAlbum, ItemTypeArticle: APITypeArticle, ItemTypeAttribute: APITypeAttribute, ItemTypeAuth: APITypeAuth, ItemTypeClassified: APITypeClassified, ItemTypeComment: APITypeComment, ItemTypeConversation: APITypeConversation, ItemTypeEvent: APITypeEvent, ItemTypeFile: APITypeFile, ItemTypeHuddle: APITypeHuddle, ItemTypeMicrocosm: APITypeMicrocosm, ItemTypePoll: APITypePoll, ItemTypeProfile: APITypeProfile, ItemTypeQuestion: APITypeQuestion, ItemTypeRole: APITypeRole, ItemTypeSite: APITypeSite, ItemTypeUpdate: APITypeUpdate, ItemTypeUpdateOptionType: APITypeUpdateOptionType, ItemTypeUser: APITypeUser, ItemTypeWatcher: APITypeWatcher, ItemTypeWhoAmI: APITypeWhoAmI, }
ItemTypesToAPIItem maps from the itemType to the APIType
var UpdateTexts = map[int64]string{ 1: UpdateTextNewComment, 2: UpdateTextReplyToComment, 3: UpdateTextMentioned, 4: UpdateTextNewCommentInHuddle, 5: UpdateTextNewEventAttendee, 6: UpdateTextNewPollVote, 7: UpdateTextEventReminder, 8: UpdateTextNewItem, 9: UpdateTextNewUser, }
UpdateTexts is a map of email titles for a given range of update_types
var UpdateTypes = map[string]int64{ UpdateTypeNewComment: 1, UpdateTypeReplyToComment: 2, UpdateTypeMentioned: 3, UpdateTypeNewCommentInHuddle: 4, UpdateTypeNewEventAttendee: 5, UpdateTypeNewPollVote: 6, UpdateTypeEventReminder: 7, UpdateTypeNewItem: 8, UpdateTypeNewUser: 9, }
UpdateTypes is a map of update_types
Functions ¶
func AttendanceStatus ¶
AttendanceStatus returns status for the given request query
func GetAttending ¶
GetAttending returns isAttending for a given request query
func GetConnection ¶
GetConnection returns a connection from the connection pool of the already instantiated db object
func GetCurrentPage ¶
GetCurrentPage returns the current page for a given offset and limit value
func GetItemAndItemType ¶
GetItemAndItemType returns the item type and id for a given request query
func GetItemTypeFromInt ¶
GetItemTypeFromInt returns the string itemType for the integer itemTypeID
func GetLimitAndOffset ¶
GetLimitAndOffset returns the Limit and Offset for a given request querystring
func GetLinkToThisPage ¶
GetLinkToThisPage returns a link to the current page
func GetMapStringFromInt ¶
GetMapStringFromInt for a given map[string]int64 return the value of the key where the value matches
func GetMaxOffset ¶
GetMaxOffset returns the maximum possible offset for a given number of pages and limit per page
func GetPageCount ¶
GetPageCount returns the number of pages for a given total and items per page
func GetTransaction ¶
GetTransaction will begin and then return a transaction on the already instantiated db object
func InitDBConnection ¶
func InitDBConnection(c DBConfig)
InitDBConnection will establish the connection to the database or die trying
func IsValidColor ¶
IsValidColor returns true if the string color is a websafe recognised color
func RandString ¶
RandString returns a random string for a required length
func TestPatch ¶
TestPatch partially implements http://tools.ietf.org/html/rfc6902
Patch examples: { "op": "test", "path": "/a/b/c", "value": "foo" }, { "op": "remove", "path": "/a/b/c" }, { "op": "add", "path": "/a/b/c", "value": [ "foo", "bar" ] }, { "op": "replace", "path": "/a/b/c", "value": 42 }, { "op": "move", "from": "/a/b/c", "path": "/a/b/d" }, { "op": "copy", "from": "/a/b/d", "path": "/a/b/e" }
Types ¶
type ArrayType ¶
type ArrayType struct { Total int64 `json:"total"` Limit int64 `json:"limit"` Offset int64 `json:"offset"` MaxOffset int64 `json:"maxOffset"` Pages int64 `json:"totalPages"` Page int64 `json:"page"` Links []LinkType `json:"links,omitempty"` Type string `json:"type"` Items interface{} `json:"items"` }
ArrayType describes an array in JSON and how to paginate the collection
type AttachmentType ¶
type AttachmentType struct { Href string `json:"href"` Created int `json:"created"` CreatedBy string `json:"createdBy"` MimeType string `json:"mimetypes"` Bytes int `json:"bytes"` Width int `json:"width"` Height int `json:"height"` Views int `json:"views"` Thumbnail ThumbnailType `json:"thumbnail,omitempty"` }
AttachmentType describes an attachment
type CoreMetaType ¶
type CoreMetaType struct { Stats []StatType `json:"stats,omitempty"` Links []LinkType `json:"links,omitempty"` Permissions interface{} `json:"permissions,omitempty"` }
CoreMetaType is used implicitly by all meta types, and explicitly by all collections
type CreatedMetaType ¶
type CreatedMetaType struct { CreatedType ExtendedMetaType }
CreatedMetaType for items (such as Alerts) that cannot be edited but have a creator
type CreatedType ¶
type CreatedType struct { Created time.Time `json:"created"` CreatedByID int64 `json:"-"` CreatedBy interface{} `json:"createdBy"` }
CreatedType describes an author/creator
type DBConfig ¶
DBConfig stores the connection information used by InitDBConnection to establish a connection to the database
type DefaultMetaType ¶
type DefaultMetaType struct { CreatedType EditedType ExtendedMetaType }
DefaultMetaType is used by single items
type DefaultNoFlagsMetaType ¶
type DefaultNoFlagsMetaType struct { CreatedType EditedType CoreMetaType }
DefaultNoFlagsMetaType is used by single items
type DefaultReducedFlagsMetaType ¶
type DefaultReducedFlagsMetaType struct { CreatedType EditedType SimpleMetaType }
DefaultReducedFlagsMetaType is used by single items
type EditedType ¶
type EditedType struct { EditedNullable pq.NullTime `json:"-"` Edited string `json:"edited,omitempty"` EditedByNullable sql.NullInt64 `json:"-"` EditedBy interface{} `json:"editedBy,omitempty"` EditReasonNullable sql.NullString `json:"-"` EditReason string `json:"editReason,omitempty"` }
EditedType describes edited meta data
type Er ¶
type Er interface { Exec(query string, args ...interface{}) (sql.Result, error) Query(query string, args ...interface{}) (*sql.Rows, error) QueryRow(query string, args ...interface{}) *sql.Row }
Er provides an interface that both sql.DB and sql.Tx fulfil, allowing for generic funcs that either can use.
type ExtendedMetaType ¶
type ExtendedMetaType struct { Flags FlagsType `json:"flags,omitempty"` CoreMetaType }
ExtendedMetaType is used implicitly by all meta types, and explicitly by all collections
type FlagsType ¶
type FlagsType struct { Sticky interface{} `json:"sticky,omitempty"` Open interface{} `json:"open,omitempty"` Deleted interface{} `json:"deleted,omitempty"` Moderated interface{} `json:"moderated,omitempty"` Visible interface{} `json:"visible,omitempty"` Unread interface{} `json:"unread,omitempty"` Watched interface{} `json:"watched,omitempty"` Ignored interface{} `json:"ignored,omitempty"` SendEmail interface{} `json:"sendEmail,omitempty"` SendSMS interface{} `json:"sendSMS,omitempty"` Attending interface{} `json:"attending,omitempty"` }
FlagsType describes the common flags
func (*FlagsType) SetVisible ¶
func (f *FlagsType) SetVisible()
SetVisible determines whether the item should be visible and if so sets the visible flag
type LinkArrayType ¶
type LinkArrayType struct {
Links []LinkType `json:"links"`
}
LinkArrayType is a collection of links
type LinkType ¶
type LinkType struct { Rel string `json:"rel,omitempty"` // REST Href string `json:"href"` Title string `json:"title,omitempty"` Text string `json:"text,omitempty"` // HTML }
LinkType is a link
func GetArrayLinks ¶
GetArrayLinks returns a collection of valid links for navigating a collection of items
type PatchType ¶
type PatchType struct { Operation string `json:"op"` Path string `json:"path"` From string `json:"from,omitempty"` RawValue interface{} `json:"value,omitempty"` Bool sql.NullBool `json:"-"` String sql.NullString `json:"-"` Int64 sql.NullInt64 `json:"-"` Time pq.NullTime `json:"-"` }
PatchType describes a JSON PATCH
func (*PatchType) ScanRawValue ¶
ScanRawValue scans a PATCH value
type SimpleFlagsType ¶
type SimpleFlagsType struct { Deleted bool `json:"deleted"` Moderated bool `json:"moderated"` Visible bool `json:"visible"` }
SimpleFlagsType describes simple flags
type SimpleMetaType ¶
type SimpleMetaType struct { Flags SimpleFlagsType `json:"flags,omitempty"` CoreMetaType }
SimpleMetaType is used explicitly by comments
type SummaryMetaType ¶
type SummaryMetaType struct { CreatedType ExtendedMetaType }
SummaryMetaType is used by summary of single items