Documentation ¶
Overview ¶
Package sqlx is PostgreSQL and SQLite database access layer (DAL) for users and posts.
The package contains three files: * connection.go, which handles the actual database connection as singleton * posts.go, which handles CRUD methods for posts * users.go, which handles CRUD methods for users * email.go, which handles method for sending email to users * settings.go, which handles CU methods for settings
All methods defined this package should be implemented in other drivers as well, unless specifically said otherwise.
Index ¶
- Variables
- func CompareHash(digest []byte, password string) bool
- func Drop()
- func GenerateHash(password string) ([]byte, error)
- type Email
- type Post
- type RecipientStruct
- type User
- func (user User) ExpireRecovery(t time.Duration)
- func (user User) Get() (User, error)
- func (user User) GetAll() ([]User, error)
- func (user User) GetByEmail() (User, error)
- func (user User) Insert() (User, error)
- func (user User) Login() (User, error)
- func (user User) PasswordReset(entry User) (User, error)
- func (user User) Recover() error
- func (user User) SendRecoveryEmail() error
- func (user User) Update(entry User) (User, error)
- type Vertigo
Constants ¶
This section is empty.
Variables ¶
var Driver = flag.String("driver", "sqlite3", "Database driver to use (sqlite3, mysql, postgres)")
var RecoveryTemplate = `` /* 200-byte string literal not displayed */
var Source = flag.String("source", "vertigo.db", "Database data source")
Functions ¶
func CompareHash ¶
CompareHash compares bcrypt password with a plaintext one. Returns true if passwords match and false if they do not.
func GenerateHash ¶
GenerateHash generates bcrypt hash from plaintext password
Types ¶
type Email ¶
type Email struct { Sender string Host string Recipient RecipientStruct }
Email holds data of email sender and recipient for easier handling in templates.
type Post ¶
type Post struct { ID int64 `json:"id"` Title string `json:"title" form:"title" binding:"required"` Content string `json:"content"` Markdown string `json:"markdown" form:"markdown"` Slug string `json:"slug"` Author int64 `json:"author"` Excerpt string `json:"excerpt"` Viewcount uint `json:"viewcount"` Published bool `json:"-"` Created int64 `json:"created"` Updated int64 `json:"updated"` TimeOffset int `json:"timeoffset"` }
Post struct contains all relevant data when it comes to posts. Most fields are automatically filled when inserting new object into the database. JSON field after type refer to JSON key which martini will use to render data. Form field refers to frontend POST form `name` fields which martini uses to read data from. Binding defines whether the field is required when inserting or updating the object.
func (Post) Delete ¶
Delete or post.Delete deletes a post according to post.Slug. Requires session cookie. Returns error object.
func (Post) Get ¶
Get or user.Get returns user according to given user.Slug. Requires session session as a parameter. Returns Ad and error object.
func (Post) GetAll ¶
GetAll or user.GetAll returns all user in database. Returns []User and error object.
func (Post) Increment ¶
func (post Post) Increment()
Update or user.Update updates parameter "entry" with data given in parameter "user". Returns updated Ad object and an error object.
type RecipientStruct ¶
RecipientStruct holds data of email recipient for easier handling in templates.
type User ¶
type User struct { ID int64 `json:"id"` Name string `json:"name" form:"name"` Password string `json:"password,omitempty" form:"password" sql:"-"` Recovery string `json:"-"` Digest []byte `json:"-"` Email string `json:"email" form:"email" binding:"required"` Posts []Post `json:"posts"` Location string `json:"location" form:"location"` }
User struct holds all relevant data for representing user accounts on Vertigo. A complete User struct also includes Posts field (type []Post) which includes all posts made by the user.
func (User) ExpireRecovery ¶
ExpireRecovery or user.ExpireRecovery sets a TTL according to t to a recovery hash. This function is supposed to be run as goroutine to avoid blocking exection for t.
func (User) Get ¶
Get or user.Get returns user according to given user.Slug. Requires session session as a parameter. Returns Ad and error object.
func (User) GetAll ¶
GetAll or user.GetAll fetches all users with post data merged from the database.
func (User) GetByEmail ¶
GetByEmail or user.GetByEmail returns User object according to given .Email with post information merged.
func (User) Insert ¶
Insert or user.Insert inserts a new User struct into the database. The function creates .Digest hash from .Password.
func (User) Login ¶
Login or user.Login is a function which retrieves user according to given .Email field. The function then compares the retrieved object's .Digest field with given .Password field. If the .Password and .Digest match, the function returns the requested User struct, but with the .Password and .Digest omitted.
func (User) Recover ¶
Recover or user.Recover is used to recover User's password according to user.Email The function will insert user.Recovery field with generated UUID string and dispatch an email to the corresponding user.Email address. It will also add TTL to Recovery field.
func (User) SendRecoveryEmail ¶
SendRecoveryEmail dispatches predefined recovery email to recipient defined in parameters. Makes use of https://gist.github.com/andelf/5004821
type Vertigo ¶
type Vertigo struct { ID int `json:"-,omitempty"` Name string `json:"name" form:"name" binding:"required"` Hostname string `json:"hostname" form:"hostname" binding:"required"` Firstrun bool `json:"firstrun,omitempty"` CookieHash string `json:"cookiehash,omitempty"` AllowRegistrations bool `json:"allowregistrations" form:"allowregistrations"` Description string `json:"description" form:"description" binding:"required"` MailerLogin string `json:"mailerlogin" form:"mailerlogin"` MailerPort int `json:"mailerport" form:"mailerport"` MailerPassword string `json:"mailerpassword" form:"mailerpassword"` MailerHostname string `json:"mailerhostname" form:"mailerhostname"` }
Vertigo struct is used as a site wide settings structure. Firstrun and CookieHash are generated and controlled by the application and should not be rendered or made editable anywhere on the site.
var Settings *Vertigo
func VertigoSettings ¶
func VertigoSettings() *Vertigo
VertigoSettings populates the global Settings object with data from database. If no records exist, it creates one.
func (Vertigo) Get ¶
Get or settings.Get returns settings saved to database. Returns Vertigo and error object.