Documentation ¶
Index ¶
- func CreateOwner(config DBConfig, password string) error
- func NewEmptyPost(ctype string) smolboard.Post
- func NewZeroID(t time.Time) int64
- func ValidateUser(username, password string) error
- func VerifyPassword(hash []byte, password string) error
- type DBConfig
- type Database
- type Transaction
- func (d *Transaction) ChangePassword(password string) error
- func (tx *Transaction) Commit() error
- func (d *Transaction) CreateToken(uses int) (*smolboard.Token, error)
- func (d *Transaction) DeleteAllSessions() error
- func (d *Transaction) DeletePost(id int64) error
- func (d *Transaction) DeleteSessionID(id int64) error
- func (d *Transaction) DeleteToken(token string) error
- func (d *Transaction) DeleteUser(username string) error
- func (tx *Transaction) Exec(query string, args ...interface{}) (sql.Result, error)
- func (d *Transaction) HasPermOverUser(min smolboard.Permission, user string) error
- func (d *Transaction) HasPermission(min smolboard.Permission, inclusive bool) error
- func (d *Transaction) IsUserOrHasPermOver(min smolboard.Permission, user string) error
- func (d *Transaction) ListTokens() (*smolboard.TokenList, error)
- func (d *Transaction) Me() (*smolboard.UserPart, error)
- func (d *Transaction) Permission() (perm smolboard.Permission, err error)
- func (d *Transaction) Post(id int64) (*smolboard.PostExtended, error)
- func (d *Transaction) PostQuickGet(id int64) (*smolboard.Post, error)
- func (d *Transaction) PostSearch(q string, count, page uint) (smolboard.SearchResults, error)
- func (d *Transaction) Posts(count, page uint) (smolboard.SearchResults, error)
- func (d *Transaction) PromoteUser(username string, p smolboard.Permission) error
- func (tx *Transaction) Query(query string, args ...interface{}) (*sql.Rows, error)
- func (tx *Transaction) QueryRow(query string, args ...interface{}) *sql.Row
- func (tx *Transaction) QueryRowx(query string, args ...interface{}) *sqlx.Row
- func (tx *Transaction) Queryx(query string, args ...interface{}) (*sqlx.Rows, error)
- func (tx *Transaction) Rollback() error
- func (d *Transaction) SavePost(post *smolboard.Post) error
- func (d *Transaction) SearchTag(part string) ([]smolboard.PostTag, error)
- func (d *Transaction) SearchUsers(qs string, count, page uint) (smolboard.UserList, error)
- func (d *Transaction) SessionFromID(id int64) (s *smolboard.Session, err error)
- func (d *Transaction) Sessions() ([]smolboard.Session, error)
- func (d *Transaction) SetPostPermission(id int64, target smolboard.Permission) error
- func (d *Transaction) Signin(user, pass, UA string) (*smolboard.Session, error)
- func (d *Transaction) Signout() error
- func (d *Transaction) Signup(user, pass, token, UA string) (*smolboard.Session, error)
- func (d *Transaction) TagPost(postID int64, tag string) error
- func (d *Transaction) UntagPost(postID int64, tag string) error
- func (d *Transaction) User(username string) (*smolboard.UserPart, error)
- func (d *Transaction) Users(count, page uint) (smolboard.UserList, error)
- type TxHandler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CreateOwner ¶
CreateOwner initializes the database once then creates the owner account.
func NewEmptyPost ¶
func ValidateUser ¶
func VerifyPassword ¶
Types ¶
type DBConfig ¶
type Transaction ¶
type Transaction struct { // use a .Conn instead to allow concurrent transactions. *sqlx.Conn // As we acquire an entire transaction, it is safe to store our own local // session state as long as we keep it up to date on our own calls. Session smolboard.Session // contains filtered or unexported fields }
Transaction is a concurrent transaction in SQLite. The transaction is only truly committed once Commit is actually called, which would then lock the database.
func BeginTx ¶
BeginTx starts a new transaction belonging to the given session. If session is empty, then a transaction is not opened.
func (*Transaction) ChangePassword ¶
func (d *Transaction) ChangePassword(password string) error
func (*Transaction) Commit ¶
func (tx *Transaction) Commit() error
Commit commits the changes. It does not close the transaction.
func (*Transaction) CreateToken ¶
func (d *Transaction) CreateToken(uses int) (*smolboard.Token, error)
func (*Transaction) DeleteAllSessions ¶
func (d *Transaction) DeleteAllSessions() error
DeleteAllSessions deletes all sessions except the current one.
func (*Transaction) DeletePost ¶
func (d *Transaction) DeletePost(id int64) error
func (*Transaction) DeleteSessionID ¶
func (d *Transaction) DeleteSessionID(id int64) error
DeleteSessionID deletes the person's own session ID.
func (*Transaction) DeleteToken ¶
func (d *Transaction) DeleteToken(token string) error
func (*Transaction) DeleteUser ¶
func (d *Transaction) DeleteUser(username string) error
func (*Transaction) Exec ¶
func (tx *Transaction) Exec(query string, args ...interface{}) (sql.Result, error)
Exec calls ExecContext.
func (*Transaction) HasPermOverUser ¶
func (d *Transaction) HasPermOverUser(min smolboard.Permission, user string) error
HasPermOverUser checks that the current user has at least the given minimum permission and has a higher permission than the target user.
func (*Transaction) HasPermission ¶
func (d *Transaction) HasPermission(min smolboard.Permission, inclusive bool) error
HasPermission returns nil if the user has the given permission. If inclusive is true, then nil is returned if the user has the same permission as min.
func (*Transaction) IsUserOrHasPermOver ¶
func (d *Transaction) IsUserOrHasPermOver(min smolboard.Permission, user string) error
func (*Transaction) ListTokens ¶
func (d *Transaction) ListTokens() (*smolboard.TokenList, error)
func (*Transaction) Permission ¶
func (d *Transaction) Permission() (perm smolboard.Permission, err error)
Permission scans for the permissions, or returns action not permitted if the user does not exist.
func (*Transaction) Post ¶
func (d *Transaction) Post(id int64) (*smolboard.PostExtended, error)
Post returns a single post with the ID. It returns a post not found error if the post is not found or the user does not have permission to see the post.
func (*Transaction) PostQuickGet ¶
func (d *Transaction) PostQuickGet(id int64) (*smolboard.Post, error)
PostQuickGet gets a normal post instance. This function is used primarily internally, but exported for local use.
func (*Transaction) PostSearch ¶
func (d *Transaction) PostSearch(q string, count, page uint) (smolboard.SearchResults, error)
PostSearch parses the query string and returns the searched posts.
func (*Transaction) Posts ¶
func (d *Transaction) Posts(count, page uint) (smolboard.SearchResults, error)
Posts returns the list of posts that's paginated. Count represents the limit for each page and page represents the page offset 0-indexed.
func (*Transaction) PromoteUser ¶
func (d *Transaction) PromoteUser(username string, p smolboard.Permission) error
PromoteUser promotes or demotes someone else.
func (*Transaction) Query ¶
func (tx *Transaction) Query(query string, args ...interface{}) (*sql.Rows, error)
Query calls QueryContext.
func (*Transaction) QueryRow ¶
func (tx *Transaction) QueryRow(query string, args ...interface{}) *sql.Row
QueryRow calls QueryRowContext.
func (*Transaction) QueryRowx ¶
func (tx *Transaction) QueryRowx(query string, args ...interface{}) *sqlx.Row
QueryRowx calls QueryRowxContext.
func (*Transaction) Queryx ¶
func (tx *Transaction) Queryx(query string, args ...interface{}) (*sqlx.Rows, error)
Queryx calls QueryxContext.
func (*Transaction) Rollback ¶
func (tx *Transaction) Rollback() error
Rollback rolls back the transaction and closes it. This method must ALWAYS be called when done.
func (*Transaction) SearchTag ¶
func (d *Transaction) SearchTag(part string) ([]smolboard.PostTag, error)
SearchTag searches for tags and returns at max 25 tags. It returns only the count and name.
func (*Transaction) SearchUsers ¶
func (*Transaction) SessionFromID ¶
func (d *Transaction) SessionFromID(id int64) (s *smolboard.Session, err error)
SessionFromID returns a queried session from the database. It returns the current session state if the ID matches.
func (*Transaction) Sessions ¶
func (d *Transaction) Sessions() ([]smolboard.Session, error)
Sessions returns a list of sessions. The sessions will not have an AuthToken unless it is the current session. The sessions will be sorted from newest to oldest.
func (*Transaction) SetPostPermission ¶
func (d *Transaction) SetPostPermission(id int64, target smolboard.Permission) error
SetPostPermission sets the post's permission. The current user can set the post's permission to as high as their own if this is their post or if the user is an administrator.
func (*Transaction) Signin ¶
func (d *Transaction) Signin(user, pass, UA string) (*smolboard.Session, error)
Signin creates a new session using the given username and password. The UserAgent will be used for listing sessions. This function returns an authenticate token.
func (*Transaction) Signout ¶
func (d *Transaction) Signout() error
func (*Transaction) Signup ¶
func (d *Transaction) Signup(user, pass, token, UA string) (*smolboard.Session, error)
type TxHandler ¶
type TxHandler = func(*Transaction) error