models

package
v0.0.0-...-66bfd90 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2020 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EntriesByYear

func EntriesByYear(entries []*Entry) map[int][]*Entry

EntriesByYear re-organizes a map of Entries to group them by year

Types

type Comment

type Comment struct {
	ID         int
	EntryID    int
	TimePosted time.Time
	Name       string `form:"name"`
	Email      string `form:"email"`
	Text       string `form:"comment"`
}

Comment encapsulates a blog entry comment

type CommentManager

type CommentManager struct {
	ConnStr string
}

CommentManager is a SQL-based manager for comment records

func (*CommentManager) CreateTable

func (mgr *CommentManager) CreateTable() error

CreateTable creates an SQL table for storing blog entries

func (*CommentManager) GetAll

func (mgr *CommentManager) GetAll() []*Comment

GetAll returns all Comment records from a SQL table

func (*CommentManager) GetByEntry

func (mgr *CommentManager) GetByEntry(entryID int) []*Comment

GetByEntry returns all Comment records for a given Entry from a SQL table

func (*CommentManager) GetOne

func (mgr *CommentManager) GetOne(commentID int) *Comment

GetOne returns a single Comment record from a SQL table

func (*CommentManager) InsertMany

func (mgr *CommentManager) InsertMany(comments []*Comment)

InsertMany is analogous to InsertOne, but accepts a map of Comment records

func (*CommentManager) InsertOne

func (mgr *CommentManager) InsertOne(comment *Comment)

InsertOne inserts a single Comment record into a SQL table

type Entry

type Entry struct {
	ID         int
	Title      string
	DatePosted time.Time
	Tags       []string
}

Entry is a definition for blog Entry objects

type EntryManager

type EntryManager struct {
	ConnStr string
}

EntryManager is a SQL-based manager for Entry records

func (*EntryManager) CreateTable

func (mgr *EntryManager) CreateTable() error

CreateTable creates an SQL table for storing blog entries

func (*EntryManager) GetAll

func (mgr *EntryManager) GetAll() []*Entry

GetAll returns all Entry records from a SQL table

func (*EntryManager) GetOne

func (mgr *EntryManager) GetOne(entryID int) *Entry

GetOne returns a single Entry record from a SQL table

func (*EntryManager) InsertMany

func (mgr *EntryManager) InsertMany(entries []*Entry)

InsertMany is analogous to InsertOne, but accepts a map of Entry records

func (*EntryManager) InsertOne

func (mgr *EntryManager) InsertOne(entry *Entry)

InsertOne inserts a single Entry record into a SQL table

type ScoreManager

type ScoreManager struct {
	Conn *redis.Client
}

ScoreManager is responsible for setting/getting metrics in Redis

func (*ScoreManager) AddVisit

func (mgr *ScoreManager) AddVisit()

AddVisit increments the global visitor/hit counter and the daily counter

func (*ScoreManager) GetLikes

func (mgr *ScoreManager) GetLikes(entryID int) int

GetLikes returns the "likes" score for a blog entry key

func (*ScoreManager) GetSession

func (mgr *ScoreManager) GetSession(sessionID string) (string, bool)

GetSession gets the user session key from Redis

func (*ScoreManager) GetVisits

func (mgr *ScoreManager) GetVisits() int

GetVisits gets the value of the global visitor/hit counter

func (*ScoreManager) LikeEntry

func (mgr *ScoreManager) LikeEntry(sessionID string, entryID int)

LikeEntry bumps the "likes" score for a blog entry key

func (*ScoreManager) SetLikedBy

func (mgr *ScoreManager) SetLikedBy(sessionID string, entryID int)

SetLikedBy attaches a user session ID to a blog entry key

func (*ScoreManager) SetSession

func (mgr *ScoreManager) SetSession(sessionID string)

SetSession sets the user session key in Redis

func (*ScoreManager) WasLikedBy

func (mgr *ScoreManager) WasLikedBy(sessionID string, entryID int) bool

WasLikedBy checks whether a blog entry was liked by a specific user

Jump to

Keyboard shortcuts

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