Documentation
¶
Index ¶
- func Auth0Login(ctx context.Context, code string, state string) (string, int, error)
- func DoSearch(ctx context.Context, q url.Values) (*models.SearchResults, int, error)
- func GetCommentAttachments(ctx context.Context, commentID int64) (*models.Attachments, int, error)
- func GetConversation(ctx context.Context, conversationID int64, jumpTo string, query url.Values) (*models.Conversation, int, error)
- func GetHuddles(ctx context.Context, query url.Values) (*models.Huddles, int, error)
- func GetMicrocosm(ctx context.Context, microcosmID int64) (*models.Microcosm, int, error)
- func GetProfile(ctx context.Context, profileID int64) (*models.Profile, int, error)
- func GetProfiles(ctx context.Context, query url.Values) (*models.Profiles, int, error)
- func GetUpdates(ctx context.Context, q url.Values) (*models.UpdatesResults, int, error)
- func NewCache(addr string)
- func ProfileFromAPIContext(ctx context.Context) (*models.Profile, int, error)
- func RootFromRequest(req *http.Request) (string, int, error)
- func SiteFromAPIContext(ctx context.Context) (*models.Site, int, error)
- type CommentForm
- type Params
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Auth0Login ¶
Auth0Login consumes the auth0 code and will use the microcosm API to fetch a microcosm access_token
func GetCommentAttachments ¶
GetCommentAttachments returns attachments for a given comment
func GetConversation ¶
func GetConversation(ctx context.Context, conversationID int64, jumpTo string, query url.Values) (*models.Conversation, int, error)
GetConversation returns a conversation if this user (defined by context) has permission to view it
func GetHuddles ¶
GetHuddles returns a list of huddles for a given search.
func GetMicrocosm ¶
GetMicrocosm returns a microcosm if this user (defined by context) has permission to view it
func GetProfile ¶
GetProfile returns a single profile for a given search.
func GetProfiles ¶
GetProfiles returns a list of profiles for a given search.
func GetUpdates ¶
GetUpdates returns the personalised list of items that have been updated for the given user (defined by context)
func NewCache ¶
func NewCache(addr string)
NewCache will create an API cache for a given memcached server address
func ProfileFromAPIContext ¶
ProfileFromAPIContext is used to return the current profile of the site based on the /whoami call determined by the apiroot that is within the context and the access token also in the context
func RootFromRequest ¶
RootFromRequest returns the URL of the API for the site associated with the request, i.e. https://subdomain.apidomain.tld/api/v1
Types ¶
type CommentForm ¶
type CommentForm struct {
ID int64 `json:"id"`
ItemType string `json:"itemType" validate:"required"`
ItemID int64 `json:"itemId" validate:"required"`
InReplyTo int64 `json:"inReplyTo"`
Markdown string `json:"markdown" validate:"required,max=50000"`
Attachments int64 `json:"attachments"`
}
CommentForm is a comment as the form posts it.
We define this here even though it's a valid subset of the Comment struct and we could've used that, this will give us more protection against attacks that targeted the unreferenced fields. In this, only the fields that a form could populate are provided, the we will perform the mapping to the models/comment.go within the controller, which is inaccessible to an attacker.
In essence this is the write path, and non-Form structs are the read path and that abstraction protects us. It also allows us to define validation here.
type Params ¶
type Params struct {
Ctx context.Context
// Type corresponds to the top level API path.
// i.e. comments, conversation, events, huddles, legal, microcosms, polls, profiles, roles, updates, users, watchers
Type string
// TypeID corresponds to a single item of the given Type
TypeID string
// Part corresponds to a child of the Type and TypeID
// i.e. /comments/17/attachments
// This would make Part = "attachments"
Part string
// PartID corresponds to a single item of the given Part for the given Type and TypeID
// i.e. /comments/17/attachments/<filehash>
// This would make PartID = "<filehash>" (assume a SHA file hash is the actual value)
PartID string
// Part2 corresponds to a child of the Part
// i.e. /microcosms/31/roles/18/profiles
// This would make Part2 = "profiles"
Part2 string
// Part2ID corresponds to a single item of the given Part2, for the Given Type + TypeID + Part + PartID
// i.e. //microcosms/31/roles/18/profiles/68
// This would make Part2ID = "68"
Part2ID string
// Q is the query string
Q url.Values
}
Params is a deconstruction of a Microcosm API URL into constiuent parts that can be built up to form an API request.
For examples of URLs, see the Microcosm API server handlers.