Documentation ¶
Overview ¶
Package db defines the requirements for our database, via the Store interface, and implements it for postgres.
Index ¶
- Variables
- type Group
- type GroupMember
- type PGStore
- func (pg *PGStore) AddGroup(u User, groupname string) error
- func (pg *PGStore) AddUser(username string, hash []byte) error
- func (pg *PGStore) ExecuteSchema(filename string) error
- func (pg *PGStore) GetGroupByID(id string) (Group, []GroupMember, error)
- func (pg *PGStore) GetGroupsForUser(u User) ([]Group, error)
- func (pg *PGStore) GetUserByName(username string) (*User, error)
- func (pg *PGStore) Query(query string, args ...interface{}) (*sql.Rows, error)
- func (pg *PGStore) RevokeSession(session string) error
- func (pg *PGStore) SessionGet(session string, newExpiration time.Time) (*Session, error)
- func (pg *PGStore) UserAddSession(user User, session string, expires time.Time) error
- type Session
- type Store
- type User
Constants ¶
This section is empty.
Variables ¶
var ( // ErrUsernameExists is returned when the unique requirement of a username is violated ErrAlreadyExists = errors.New("DB: Username exists") // ErrNotFound is returned when the requested value isn't found ErrNotFound = errors.New("DB: Not Found") )
Functions ¶
This section is empty.
Types ¶
type Group ¶
A Group is the unit of sharing - All of the users in the group can see the content shared with that group
type GroupMember ¶
type PGStore ¶
type PGStore struct {
// contains filtered or unexported fields
}
A PGStore implements storage against PostGres
func NewPGStore ¶
NewPGStore connects to a postgresql database
func (*PGStore) AddUser ¶
AddUser adds a user to the users table of the database, hashing the password with bcrypt
func (*PGStore) ExecuteSchema ¶
ExecuteSchema runs all the sql commands in the given file to initialize the database
func (*PGStore) GetGroupByID ¶
func (pg *PGStore) GetGroupByID(id string) (Group, []GroupMember, error)
GetGroupByID returns a group and a list of all its members
func (*PGStore) GetGroupsForUser ¶
GetGroupsForUser returns all the groups a user can access
func (*PGStore) GetUserByName ¶
GetUserByName returns the DB user information for a user if that user exists
func (*PGStore) RevokeSession ¶
RevokeSession removes a user's session from the sessions table
func (*PGStore) SessionGet ¶
SessionGet checks the database for a session and returns it if found If the session is absent, an error is returned. SessionGet will not return an expired session.
type Store ¶
type Store interface { ExecuteSchema(filename string) error AddUser(username string, hash []byte) error GetUserByName(username string) (*User, error) UserAddSession(user User, session string, expires time.Time) error AddGroup(u User, name string) error GetGroupsForUser(u User) ([]Group, error) GetGroupByID(id string) (Group, []GroupMember, error) // SessionGet returns a valid session if one exists. // Guaranteed to not return expired sessions. // If a valid session is found, extend it! I don't recommend passing in a // time that's past, though. SessionGet(session string, newExpiration time.Time) (*Session, error) RevokeSession(session string) error }
A Store provides the methods required to access the database.