models

package
v0.0.0-...-ef76b7a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 1, 2014 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func UnapprovedCommentsCount

func UnapprovedCommentsCount(db *sql.DB) (int, error)

func UserCount

func UserCount(db *sql.DB) int

UserCount gets the number of users already in the database.

Types

type Comment

type Comment struct {
	Id       int64  `form:"-"`
	Created  int64  `form:"-"`
	Email    string `binding:"required" form:"email"`
	Name     string `binding:"required" form:"name"`
	Body     string `binding:"required" form:"body"`
	Url      string `binding:"required" form:"url"`
	ClientIp string `form:"-"`
	Approved bool   `form:"-"`
}

Comment represents a single comment with all its associated data.

func AllComments

func AllComments(db *sql.DB, url string) []Comment

func AllCommentsPaginated

func AllCommentsPaginated(db *sql.DB, page int) ([]Comment, int)

func ApprovedComments

func ApprovedComments(db *sql.DB, url string, email string) []Comment

func GetComment

func GetComment(db *sql.DB, id int) *Comment

func NewComment

func NewComment(email, name, title, body, url, ip string) Comment

NewComment creates a comment and sets the current time as its Created date.

func UnapprovedComments

func UnapprovedComments(db *sql.DB) []Comment

func (*Comment) Delete

func (c *Comment) Delete(db *sql.DB) error

func (*Comment) MarshalJSON

func (c *Comment) MarshalJSON() ([]byte, error)

MarshalJSON implements the Marshal interface to serialize the comment.

func (*Comment) Save

func (c *Comment) Save(db *sql.DB) error

func (*Comment) Validate

func (c *Comment) Validate() (bool, map[string]string)

type Config

type Config struct {
	General struct {
		Approval  bool
		Origin    []string
		Markdown  bool
		Secret    string
		Templates string
		Prefix    string
	}
	Database struct {
		Driver string
		Access string
	}
	Rate_Limit struct {
		Enable       bool
		Max_Comments int64
		Seconds      int64
	}
	Email struct {
		Notify   bool
		From     string
		To       []string
		Username string
		Password string
		Host     string
		Port     int
	}
}

Config represents the user's config that's read from a gcfg file.

func LoadConfig

func LoadConfig(path string) (Config, error)

LoadConfig loads the config from disc and outputs an error if the file could no be read.

type PaginatedComments

type PaginatedComments struct {
	TotalPages int
	Page       int
	PerPage    int
	Comments   []Comment
}

PaginatedComments helps to easily divide a set of Comments into TotalPages/PerPage slices.

type User

type User struct {
	Id       int64  `form:"-"`
	Created  int64  `form:"-"`
	Email    string `binding:"required" form:"email"`
	Password string `binding:"required" form:"password"`
}

User is a backend user/admin.

func NewUser

func NewUser(email, password string) User

NewUser creates a new user while automatically hashing the password.

func UserByEmail

func UserByEmail(db *sql.DB, email string) (User, error)

func UserById

func UserById(db *sql.DB, id int64) (User, error)

func (*User) Save

func (u *User) Save(db *sql.DB) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL