Documentation ¶
Index ¶
- func CheckSafe(directory string, base string) bool
- func CreateFilePath(dir string, name string) string
- func DeleteComment(id int64) error
- func DeleteFileByID(id int64) error
- func DeleteOldTags() error
- func DeletePostById(id int64) error
- func DeletePostTagsByPostId(post_id int64) error
- func EncryptPassword(password string) (string, error)
- func GenerateJWTKeys(bits int) ([]byte, []byte, error)
- func GenerateSlug(input string, table string) string
- func GetNumberOfComments() (int64, error)
- func GetNumberOfFileDbItem() (int64, error)
- func GetNumberOfPosts(isPage bool, published bool) (int64, error)
- func GetNumberOfUsers() (int64, error)
- func GetSettingValue(k string) string
- func Initialize(dbPath string, dbExists bool) error
- func InitializeKey(privKeyPath, pubKeyPath string)
- func InsertPostTag(postID int64, tagID int64) error
- func InsertRoleUser(role_id int, user_id int64) error
- func PostChangeSlug(slug string) bool
- func SetMessageGenerator(name string, fn func(v interface{}) string)
- func SetNavigators(labels, urls []string) error
- func SetSettingIfNotExists(k, v, t string) error
- func ValidateJWT(t string) (*jwt.Token, error)
- type Comment
- type Comments
- type File
- type FileDb
- type FileDbItem
- type JWT
- type Message
- type Messages
- type Navigator
- type NullTime
- type Post
- func (p *Post) Author() *User
- func (p *Post) Comments() []*Comment
- func (p *Post) Excerpt() string
- func (post *Post) GetPostById(id ...int64) error
- func (p *Post) GetPostBySlug(slug string) error
- func (p *Post) Insert() error
- func (p *Post) Publish(by int64) error
- func (p *Post) Save(tags ...*Tag) error
- func (p *Post) Summary() string
- func (p *Post) TagString() string
- func (p *Post) Tags() []*Tag
- func (p *Post) Update() error
- func (p *Post) UpdateFromJSON(j []byte) error
- func (p *Post) UpdateFromRequest(r *http.Request)
- func (p *Post) Url() string
- type Posts
- func (p Posts) AppendPosts(posts Posts)
- func (p Posts) Get(i int) *Post
- func (p *Posts) GetAllPostList(isPage bool, onlyPublished bool, orderBy string) error
- func (p *Posts) GetAllPostsByTag(tagId int64) error
- func (posts *Posts) GetPostList(page, size int64, isPage bool, onlyPublished bool, orderBy string) (*utils.Pager, error)
- func (p *Posts) GetPostsByTag(tagId, page, size int64, onlyPublished bool) (*utils.Pager, error)
- func (p Posts) Len() int
- type Row
- type Setting
- type Settings
- type Statis
- type Tag
- type Tags
- type Token
- type User
- func (u *User) Avatar() string
- func (u *User) ChangePassword(password string) error
- func (u *User) CheckPassword(password string) bool
- func (u *User) Create(password string) error
- func (u *User) GetUserByEmail() error
- func (u *User) GetUserById() error
- func (u *User) GetUserByName() error
- func (u *User) GetUserBySlug() error
- func (u *User) Insert() error
- func (u *User) Save() error
- func (u *User) Update() error
- func (u User) UserEmailExist() bool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CheckSafe ¶
CheckSafe checks if the directory is a child directory of base, to make sure that GetFileList won't read any folder other than the upload folder.
func CreateFilePath ¶
CreateFilePath creates a filepath from the given directory and name, returning the name of the newly created filepath.
func DeleteComment ¶
DeleteComment deletes the comment with the given ID from the DB.
func DeleteFileByID ¶
DeleteFileByID deletes the given file id from the DB.
func DeletePostById ¶
DeletePostById deletes the given Post from the DB.
func DeletePostTagsByPostId ¶
DeletePostTagsByPostId deletes removes tags associated with the given post from the DB.
func EncryptPassword ¶
EncrypPassword hashes and salts the given password via bcrypt, returning the newly hashed and salted password.
func GenerateJWTKeys ¶
GenerateJWTKeys generates a new public/private key pair, to be used to create and validate JSON web tokens.
func GenerateSlug ¶
GenerateSlug generates a URL-friendly slug. The table is one of "posts", "tags", "navigation", or "users".
func GetNumberOfComments ¶
GetNumberOfComments returns the total number of comments in the DB.
func GetNumberOfFileDbItem ¶
GetNumberOfFileDbItem gets the total number of files in the DB.
func GetNumberOfPosts ¶
GetNumberOfPosts gets the total number of posts in the DB.
func GetNumberOfUsers ¶
GetNumberOfUsers returns the total number of users.
func GetSettingValue ¶
GetSettingValue returns the Setting value associated with the given Setting key.
func Initialize ¶
Initialize sets up the DB by creaing a new connection, creating tables if they don't exist yet, and creates the welcome data.
func InitializeKey ¶
func InitializeKey(privKeyPath, pubKeyPath string)
InitializeKey initializes the public and private keys used to create and validate JSON web tokens.
func InsertPostTag ¶
InsertPostTag saves the Post ID to the given Tag ID in the DB.
func InsertRoleUser ¶
InsertRoleUser assigns a role to the given user based on the given Role ID.
func PostChangeSlug ¶
PostChangeSlug checks to see if there is a post associated with the given slug, and returns true if there isn't.
func SetMessageGenerator ¶
SetMessageGenerator maps a message generator's name to a function.
func SetNavigators ¶
SetNavigators saves one or more label-url pairs in the site's Settings.
func SetSettingIfNotExists ¶
SetSettingIfNotExists sets the setting created by the given key-value pair if the setting does not yet exist.
Types ¶
type Comment ¶
type Comment struct { Id int64 `meddler:"id,pk"` PostId int64 `meddler:"post_id"` Author string `meddler:"author"` Email string `meddler:"author_email"` Avatar string `meddler:"author_avatar"` Website string `meddler:"author_url"` Ip string `meddler:"author_ip"` CreatedAt *time.Time `meddler:"created_at"` Content string `meddler:"content"` Approved bool `meddler:"approved"` UserAgent string `meddler:"agent"` Type string `meddler:"type"` Parent int64 `meddler:"parent"` UserId int64 `meddler:"user_id"` Children *Comments `meddler:"-"` }
A Comment defines comment item data.
func NewComment ¶
func NewComment() *Comment
NewComment returns a new comment, with the CreatedAt field set to the current time.
func (*Comment) GetCommentById ¶
GetCommentById gets a comment by its ID, and populates that comment struct with the contents for that comment from the DB.
func (*Comment) ParentComment ¶
ParentComment returns the associated parent Comment, if one exists.
func (*Comment) ParentContent ¶
ParentContent returns the parent of a given comment, if it exists. Used for threaded comments.
func (*Comment) ValidateComment ¶
ValidateComment validates a comment to ensure that all required data exists and is valid. Returns an empty string on success.
type Comments ¶
type Comments []*Comment
Comments are a slice of "Comment"s
func (*Comments) GetCommentList ¶
GetCommentList returns a new pager based on the total number of comments.
func (*Comments) GetCommentsByPostId ¶
GetCommentsByPostId gets all the comments for the given post ID.
type File ¶
A File is a file, along with a URL and last modified time.
func GetFileList ¶
GetFileList returns a slice of all Files in the given directory.
type FileDb ¶
type FileDb struct { ID int64 `meddler:"id,pk"` Name string `meddler:"name"` URL string `meddler:"url"` CreatedAt *time.Time `meddler:"created_at"` IsShowOnGallery bool `meddler:"is_show_on_gallery"` }
A FileDb defines comment item data.
func NewFileDb ¶
func NewFileDb() *FileDb
NewFileDb returns a new FileDb, with the CreatedAt field set to the current time.
func (*FileDb) GetFileByID ¶
type FileDbItem ¶
type FileDbItem []*FileDb
FileDbItem are a slice of "FileDB"s
func GetGalleryList ¶
func GetGalleryList(offset, limit int) (FileDbItem, error)
func (*FileDbItem) GetFileDbItem ¶
type JWT ¶
type JWT struct { UserRole int `json:"user_role"` UserID int64 `json:"user_id"` UserEmail string `json:"user_email"` Expiration int64 `json:"expiration"` Token string `json:"token"` }
A JWT is a JSON web token, and contains all the values necessary to create and validate tokens.
func NewJWTFromToken ¶
NewJWTFromToken returns a JWT for the given token.
type Message ¶
type Message struct { Id int `meddler:"id,pk"` Type string `meddler:"type"` Data string `meddler:"data"` IsRead bool `meddler:"is_read"` CreatedAt *time.Time `meddler:"created_at"` }
A Message is a simple bit of info, used to alert the admin on the admin panel about things like new comments, etc.
func NewMessage ¶
NewMessage creates a new message.
type Messages ¶
type Messages []*Message
Messages is a slice of "Message"s
func (*Messages) GetUnreadMessages ¶
func (m *Messages) GetUnreadMessages()
GetUnreadMessages gets all unread messages from the DB.
type Navigator ¶
type Navigator struct {}
A Navigator represents a link in the site navigation menu.
func GetNavigators ¶
func GetNavigators() []*Navigator
GetNavigators returns a slice of all Navigators.
type NullTime ¶
NullTime is an instant in time, with an extra flag to determine whether or not the time is valid. A time is considered "Valid" if it is "NOT NULL".
type Post ¶
type Post struct { Id int64 `meddler:"id,pk",json:"id"` Title string `meddler:"title",json:"title"` Slug string `meddler:"slug",json:"slug"` Markdown string `meddler:"markdown",json:"markdown"` Html string `meddler:"html",json:"html"` Image string `meddler:"image",json:"image"` IsFeatured bool `meddler:"featured",json:"featured"` IsPage bool `meddler:"page",json:"is_page"` // Using "is_page" instead of "page" since nouns are generally non-bools AllowComment bool `meddler:"allow_comment",json:"allow_comment"` CommentNum int64 `meddler:"comment_num",json:"comment_num"` IsPublished bool `meddler:"published",json:"published"` Language string `meddler:"language",json:"language"` MetaTitle string `meddler:"meta_title",json:"meta_title"` MetaDescription string `meddler:"meta_description",json:"meta_description"` CreatedAt *time.Time `meddler:"created_at",json:"created_at"` CreatedBy int64 `meddler:"created_by",json:"created_by"` UpdatedAt *time.Time `meddler:"updated_at",json:"updated_at"` UpdatedBy int64 `meddler:"updated_by",json:"updated_by"` PublishedAt *time.Time `meddler:"published_at",json:"published_at"` PublishedBy int64 `meddler:"published_by",json:"published_by"` Hits int64 `meddler:"-"` Category string `meddler:"-"` }
A Post contains all the content required to populate a post or page on the blog. It also contains info to help sort and display the post.
func GetAllPosts ¶
func NewPost ¶
func NewPost() *Post
NewPost creates a new Post, with CreatedAt set to the current time.
func (*Post) GetPostById ¶
GetPostById gets the post based on the Post ID.
func (*Post) GetPostBySlug ¶
GetPostBySlug gets the post based on the Post Slug.
func (*Post) UpdateFromJSON ¶
func (*Post) UpdateFromRequest ¶
UpdateFromRequest updates an existing Post in the DB based on the data provided in the HTTP request.
type Posts ¶
type Posts []*Post
Posts is a slice of "Post"s
func GetPublishedPosts ¶
func GetUnpublishedPosts ¶
func (Posts) AppendPosts ¶
func (*Posts) GetAllPostList ¶
GetAllPostList gets all the posts, with the options to get only pages, or only published posts. It is also possible to order the posts, with the order by string being one of six options:
"created_at" "created_at DESC" "updated_at" "updated_at DESC" "published_at" "published_at DESC"
func (*Posts) GetAllPostsByTag ¶
GetAllPostsByTag gets all the Posts with the associated Tag.
func (*Posts) GetPostList ¶
func (posts *Posts) GetPostList(page, size int64, isPage bool, onlyPublished bool, orderBy string) (*utils.Pager, error)
GetPostList returns a new pager based on all the posts in the DB.
func (*Posts) GetPostsByTag ¶
GetPostsByTag returns a new pager based all the Posts associated with a Tag.
type Row ¶
type Row interface {
Scan(dest ...interface{}) error
}
A Row contains data that can be Scanned into a variable.
type Setting ¶
type Setting struct { Id int `meddler:"id,pk"` Key string `meddler:"key"` Value string `meddler:"value"` Type string `meddler:"type"` // general, content, navigation, custom CreatedAt *time.Time `meddler:"created_at"` CreatedBy int64 `meddler:"created_by"` UpdatedAt *time.Time `meddler:"updated_at"` UpdatedBy int64 `meddler:"updated_by"` }
A Setting is the data type that stores the blog's configuration options. It is essentially a key-value store for settings, along with a type to help specify the specific type of setting. A type can be either
general site-wide general settings content related to showing content navigation site navigation settings custom custom settings
func NewSetting ¶
NewSetting returns a new setting from the given key-value pair.
func (*Setting) GetSetting ¶
GetSetting checks if a setting exists in the DB.
type Settings ¶
type Settings []*Setting
Settings a slice of all "Setting"s
func GetCustomSettings ¶
func GetCustomSettings() *Settings
GetCustomSettings returns all custom settings.
func GetSettingsByType ¶
GetSettingsByType returns all settings of the given type, where the setting key can be one of "general", "content", "navigation", or "custom".
type Statis ¶
A Statis hold info about the site stats, including things like number of comments, posts, pages, etc.
func NewStatis ¶
func NewStatis(app *golf.Application) *Statis
NewStatis returns a new Statis, pulling most info from the DB. The application argumen is required however to determine the number of active sessions.
type Tag ¶
type Tag struct { Id int64 `meddler:"id,pk"` Name string `meddler:"name"` Slug string `meddler:"slug"` Hidden bool `meddler:"hidden"` CreatedAt *time.Time `meddler:"created_at"` CreatedBy int64 `meddler:"created_by"` UpdatedAt *time.Time `meddler:"updated_at"` UpdatedBy int64 `meddler:"updated_by"` }
A Tag is a keyword associated with a post.
func GenerateTagsFromCommaString ¶
GenerateTagsFromCommaString returns a slice of "Tag"s from the given input. The input should be a comma-seperated list of tags, like
"news,tech,outdoors"
func (*Tag) GetTagBySlug ¶
GetTagBySlug finds the tag based on the Tag's slug value.
type Tags ¶
type Tags []*Tag
Tags are a slice of "Tag"s
func (*Tags) GetAllTags ¶
GetAllTags gets all the tags in the DB.
func (*Tags) GetTagsByPostId ¶
GetTagsByPostId finds all the tags with the give PostID
type Token ¶
type Token struct { Id int64 `meddler:"id,pk"` Value string `meddler:"value"` UserId int64 `meddler:"user_id"` CreatedAt *time.Time `meddler:"created_at"` ExpiredAt *time.Time `meddler:"expired_at"` }
A Token is used to associate a user with a session.
func NewToken ¶
NewToken creates a new token from the given user. Expire is the amount of time in seconds until expiry.
func (*Token) GetTokenByValue ¶
GetTokenByValue gets a token from the DB based on it's value.
type User ¶
type User struct { Id int64 `meddler:"id,pk"` Name string `meddler:"name"` Slug string `meddler:"slug"` HashedPassword string `meddler:"password"` Email string `meddler:"email"` Image string `meddler:"image"` // NULL Cover string `meddler:"cover"` // NULL Bio string `meddler:"bio"` // NULL Website string `meddler:"website"` // NULL Location string `meddler:"location"` // NULL Accessibility string `meddler:"accessibility"` Status string `meddler:"status"` Language string `meddler:"language"` Lastlogin *time.Time `meddler:"last_login"` CreatedAt *time.Time `meddler:"created_at"` CreatedBy int `meddler:"created_by"` UpdatedAt *time.Time `meddler:"updated_at"` UpdatedBy int `meddler:"updated_by"` Role int `meddler:"-"` //1 = Administrator, 2 = Editor, 3 = Author, 4 = Owner }
A User is a user on the site.
func NewUser ¶
NewUser creates a new user from the given email and name, with the CreatedAt and UpdatedAt fields set to the current time.
func (*User) Avatar ¶
Avatar returns the Gravatar of the given user, with the Gravatar being 150px by 150px.
func (*User) ChangePassword ¶
ChangePassword changes the password for the given user.
func (*User) CheckPassword ¶
CheckPassword checks to see if the given password matches the hashed password for the given user, returning true if it's a match.
func (*User) Create ¶
Create saves a user in the DB with the given password, first hashing and salting that password via bcrypt.
func (*User) GetUserByEmail ¶
GetUserByEmail finds the user by email in the DB.
func (*User) GetUserById ¶
GetUserById finds the user by ID in the DB.
func (*User) GetUserByName ¶
GetUserByName finds the user by name in the DB.
func (*User) GetUserBySlug ¶
GetUserBySlug finds the user by their slug in the DB.
func (User) UserEmailExist ¶
UserEmailExist checks to see if the given User's email exists.