Documentation ¶
Index ¶
- func CreateAdmin(adminPwd string)
- func CreateCollections(collections []string, keys []string)
- func DeleteUserSession(displayName string) error
- func GenerateSessionKey(length int) string
- func GetAllUsers() (*[]ResponseUser, error)
- func GetMgoSession(collectionName string) (*mgo.Session, *mgo.Collection)
- func GetResponseComments(questionID bson.ObjectId) (*[]ResponseComment, error)
- func IncVotes(colType int, id bson.ObjectId, inc int) error
- func InitMongoDB(host string)
- func IsAuthenticated(r *http.Request) *string
- func QuestionIncViews(questionID bson.ObjectId) error
- func SetAuthCookies(displayName string, isAdmin bool, w http.ResponseWriter) error
- func UpdateEmail(displayName string, newEmail string) error
- func UpdatePassword(displayName string, password string) error
- func UserExists(displayName string) bool
- type Answer
- type Comment
- type FormError
- type IDKeyPair
- type NewAnswer
- type NewComment
- type NewEdit
- type NewQuestion
- type NewUser
- type NewUserLogin
- type NewVote
- type Question
- type QuestionEdit
- type ResponseAnswer
- type ResponseAnswers
- type ResponseComment
- type ResponseQuestion
- type ResponseText
- type ResponseUser
- type ResponseVote
- type SearchPage
- type SearchResult
- type User
- type UserSession
- type Vote
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CreateAdmin ¶
func CreateAdmin(adminPwd string)
func CreateCollections ¶
CreateCollections ensures that indices exist for a collection @collections: The names of the collections @keys: The names of the keys to create indices for
func DeleteUserSession ¶
func GenerateSessionKey ¶
func GetAllUsers ¶
func GetAllUsers() (*[]ResponseUser, error)
func GetMgoSession ¶
func GetMgoSession(collectionName string) (*mgo.Session, *mgo.Collection)
GetMgoSession returns a session and collection @collection: The name of the collection @return:
session: Call `defer session.Close()` on this collectionName: Perform any db operations on this
func GetResponseComments ¶
func GetResponseComments(questionID bson.ObjectId) (*[]ResponseComment, error)
GetResponseComments returns a populated ResponseComment
func IncVotes ¶
IncVotes is a generic incrementor for the .Votes properties of the
other models like Answer, Comment and Question
@colType: The type of the collection, see types.go @id: The _id of the object @inc: 1 or -1
func InitMongoDB ¶
func InitMongoDB(host string)
InitMongoDB must be called before any database operations @host: The hostname of the MongoDB server
func IsAuthenticated ¶
IsAuthenticated checks the cookies in an HTTP request for valid authentication credentials.
DO NOT pass the error back to the user, it could contain the token
func QuestionIncViews ¶
QuestionIncViews increments the page views for a question
func SetAuthCookies ¶
func SetAuthCookies( displayName string, isAdmin bool, w http.ResponseWriter) error
SetAuthCookies sets the authentication cookies
func UpdateEmail ¶
func UpdatePassword ¶
func UserExists ¶
Types ¶
type Answer ¶
type Answer struct { ID bson.ObjectId `bson:"_id,omitempty"` QuestionID bson.ObjectId UserName string Text string CreatedAt time.Time Votes int }
Answer abstracts the database schema for an answer to a Question
type Comment ¶
type Comment struct { ID bson.ObjectId `bson:"_id,omitempty"` QuestionID bson.ObjectId ParentID bson.ObjectId ParentType int UserName string Text string CreatedAt time.Time Votes int }
Comment abstracts a comment on a Question or Answer
type NewAnswer ¶
NewAnswer abstracts the body of the JSON REST call to create an answer
type NewComment ¶
type NewComment struct { QuestionID bson.ObjectId ParentID bson.ObjectId ParentType int UserName string Text string }
NewComment abstracts the body of the JSON REST call to create an comment
func (*NewComment) Create ¶
func (q *NewComment) Create() (*Comment, error)
Create converts a NewComment instance into a Comment instance that can be inserted into the database, then performs the insertion
func (*NewComment) Validate ¶
func (q *NewComment) Validate() error
Validate performs validation on NewComment that has been unmarshalled from the body of an HTTP request
type NewEdit ¶
type NewQuestion ¶
NewQuestion abstracts the body of the JSON REST call to create a question
func (*NewQuestion) Create ¶
func (q *NewQuestion) Create() (*Question, error)
Create converts a NewQuestion instance into a Question instance that can be inserted into the database, then performs the insertion
func (*NewQuestion) Update ¶
func (q *NewQuestion) Update(questionID bson.ObjectId) error
Update performs a question edit
func (*NewQuestion) Validate ¶
func (q *NewQuestion) Validate() error
Validate performs validation on NewQuestion that has been unmarshalled from the body of an HTTP request
type NewUserLogin ¶
NewUserLogin abstracts a user login
func (*NewUserLogin) Validate ¶
func (u *NewUserLogin) Validate() (bool, error)
NewUserLogin.Validate tests a set of login credentials
@return: IsAdmin, error
type NewVote ¶
type NewVote struct { ParentID bson.ObjectId QuestionID bson.ObjectId IsUp bool // true if up-vote, false if down-vote UserName string Type int }
NewVote abstracts the JSON body of an upvote or downvote to a Question, Answer or Comment
type Question ¶
type Question struct { ID bson.ObjectId `bson:"_id,omitempty"` AcceptedAnswer *bson.ObjectId UserName string LastEditedBy string Text string Title string CreatedAt time.Time Tags []string Votes int Views int64 }
Question abstracts the database schema for a question that has been asked
type QuestionEdit ¶
NewQuestion abstracts the body of the JSON REST call to create a question
type ResponseAnswer ¶
type ResponseAnswer struct { ID string QuestionID string ParentID string UserName string Text string CreatedAt time.Time Comments []ResponseComment Type int Votes int LastEditedBy string }
ResponseAnswer abstracts the JSON response for a question page load
type ResponseAnswers ¶
type ResponseAnswers []ResponseAnswer
implements sort.Interface
func GetResponseAnswers ¶
func GetResponseAnswers(questionID bson.ObjectId) (ResponseAnswers, error)
GetResponseAnswers returns a populated ResponseAnswer
func (ResponseAnswers) Len ¶
func (slice ResponseAnswers) Len() int
func (ResponseAnswers) Less ¶
func (slice ResponseAnswers) Less(i, j int) bool
func (ResponseAnswers) Swap ¶
func (slice ResponseAnswers) Swap(i, j int)
type ResponseComment ¶
type ResponseComment struct { ID string QuestionID string ParentID string ParentType int UserName string Text string CreatedAt time.Time Votes int Type int LastEditedBy string }
ResponseComment abstracts the JSON response for a question page load
type ResponseQuestion ¶
type ResponseQuestion struct { ID string QuestionID string ParentID string UserName string LastEditedBy string CreatedAt time.Time Text string Title string Tags []string Type int Comments []ResponseComment Answers ResponseAnswers Votes int Views int64 }
ResponseQuestion abstracts the JSON response for a question page load
func GetResponseQuestion ¶
func GetResponseQuestion(questionID bson.ObjectId) (*ResponseQuestion, error)
GetResponseQuestion returns a populated ResponseQuestion
type ResponseText ¶
type ResponseText struct {
Text string
}
type ResponseUser ¶
type ResponseUser struct { Email string DisplayName string IsAdmin bool Questions []SearchResult }
ResponseUser abstracts a user login
func GetResponseUser ¶
func GetResponseUser(displayName string) *ResponseUser
type ResponseVote ¶
type ResponseVote struct { ID bson.ObjectId `bson:"_id,omitempty"` Votes int // TODO: index VoteMap map[bson.ObjectId]int }
ResponseVote tallies the votes for each item
func GetResponseVotes ¶
func GetResponseVotes(questionID bson.ObjectId) (*ResponseVote, error)
GetResponseVotes returns a populated ResponseVote
type SearchPage ¶
type SearchPage struct { Message string Results []SearchResult }
type SearchResult ¶
type User ¶
type User struct { ID bson.ObjectId `bson:"_id,omitempty"` Email string DisplayName string IsAdmin bool PasswordHash []byte CreatedAt time.Time Deleted bool }
User abstracts a user login
type UserSession ¶
type UserSession struct { ID bson.ObjectId `bson:"_id,omitempty"` DisplayName string SessionKey string CreatedAt time.Time Expires time.Time }
UserSession abstracts an authenticated session cookie pair
func CreateUserSession ¶
func CreateUserSession(displayName string) (*UserSession, error)
func GetUserSession ¶
func GetUserSession(displayName string) *UserSession