Documentation ¶
Index ¶
- Constants
- type Entry
- type Guestbook
- type Reply
- type SQLiteDatabase
- func (d *SQLiteDatabase) Close() error
- func (d *SQLiteDatabase) Count() (count int64, err error)
- func (d *SQLiteDatabase) DeleteEntry(entryID int64) error
- func (d *SQLiteDatabase) DeleteReply(entryID int64) error
- func (d *SQLiteDatabase) EditEntry(entry *Entry) error
- func (d *SQLiteDatabase) EditReply(reply *Reply) error
- func (d *SQLiteDatabase) Entries(page, pageSize int64) (entries []*Entry, err error)
- func (d *SQLiteDatabase) NewEntry(entry *Entry) error
- func (d *SQLiteDatabase) NewReply(reply *Reply) error
Constants ¶
View Source
const (
// DateFormat is a format of the date and time used in a guestbook.
DateFormat = "2006-01-02 15:04:05"
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Entry ¶
type Entry struct { // ID of an entry. ID int64 `json:"entry_id"` // Created holds the date and time when an entry was created. Created time.Time `json:"created"` // Name holds a nick-/name of a guest who posted an entry. Name string `json:"name"` // Website of a guest. Can be empty. Website string `json:"website,omitempty"` // HideWebsite tells wether to hide or show guest's website. HideWebsite bool `json:"hide_website,omitempty"` // Message that a guest wrote. Message string `json:"message"` // Reply holds a reply for this entry. Reply *Reply `json:"reply,omitempty"` }
Entry holds a guestbook entry.
type Guestbook ¶
type Guestbook interface { // Entries returns a slice of guestbook entries. Entries(page, pageSize int64) ([]*Entry, error) // Count returns how much entries are in a DB. Count() (int64, error) // NewEntry inserts a given Entry into a DB. NewEntry(entry *Entry) error // EditEntry modifies the fields of an existing entry. EditEntry(entry *Entry) error // DeleteEntry removes an Entry with a given ID. DeleteEntry(entryID int64) error // NewReply inserts a given Reply into a DB. NewReply(reply *Reply) error // EditReply modifies a message field of a given Reply. EditReply(reply *Reply) error // DeleteReply removes a Reply with a given ID of an Entry. DeleteReply(entryID int64) error // Close closes a DB. Close() error }
Guestbook is an interface that should be implemented by a DB.
func NewSQLiteDB ¶
NewSQLiteDB returns an instance of a SQLite Guestbook implementation.
type Reply ¶
type Reply struct { // ID of a guestbook's entry is used when update of a reply is performed. // // Not present in JSON because a reply comes within its corresponding entry. ID int64 `json:"-"` // Created holds a date and time when a reply was created. Created time.Time `json:"created,omitempty"` // Message holds a reply's message. Message string `json:"message"` }
Reply holds a reply for a guestbook's entry.
type SQLiteDatabase ¶
type SQLiteDatabase struct {
// contains filtered or unexported fields
}
SQLiteDatabase implements a Guestbook that works with a SQLite DB under the hood.
func (*SQLiteDatabase) Close ¶
func (d *SQLiteDatabase) Close() error
func (*SQLiteDatabase) Count ¶
func (d *SQLiteDatabase) Count() (count int64, err error)
Count returns how much entries are in an `entry` table.
func (*SQLiteDatabase) DeleteEntry ¶
func (d *SQLiteDatabase) DeleteEntry(entryID int64) error
func (*SQLiteDatabase) DeleteReply ¶
func (d *SQLiteDatabase) DeleteReply(entryID int64) error
func (*SQLiteDatabase) EditEntry ¶
func (d *SQLiteDatabase) EditEntry(entry *Entry) error
func (*SQLiteDatabase) EditReply ¶
func (d *SQLiteDatabase) EditReply(reply *Reply) error
func (*SQLiteDatabase) Entries ¶
func (d *SQLiteDatabase) Entries(page, pageSize int64) (entries []*Entry, err error)
func (*SQLiteDatabase) NewEntry ¶
func (d *SQLiteDatabase) NewEntry(entry *Entry) error
NewEntry inserts a passed Entry struct and fills its ID field if successful.
func (*SQLiteDatabase) NewReply ¶
func (d *SQLiteDatabase) NewReply(reply *Reply) error
Click to show internal directories.
Click to hide internal directories.