blog

package
v0.0.0-...-7b873aa Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2017 License: GPL-3.0 Imports: 6 Imported by: 0

README

example of splitting up the site into modules

TODO

  • Make CollectionName configurable - NewMgoBlogWithCollectionName()
  • Seperate all blog/db stuff out of the handlers

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrEntryNotFound = errors.New("No Blog Entry with that ID")
	ErrBadObjectId   = errors.New("error while validating entry ID")
)

Functions

This section is empty.

Types

type Blogger

type Blogger interface {
	FindById(id string) (*Entry, error)
	LatestEntries() ([]*Entry, error)
	Delete(id string) error
	Save(*Entry) error
}

func NewMgoBlog

func NewMgoBlog(session *mgo.Session, o *Options) Blogger

type Entry

type Entry struct {
	ObjId   bson.ObjectId `bson:"_id,omitempty" form:"-"`
	Id      string        `bson:"-" form:"id"`
	Author  string        `bson:"author,omitempty" form:"-"`
	Written time.Time     `bson:"written,omitempty" form:"-"`
	Title   string        `bson:"title" form:"title" binding:"required"`
	Text    string        `bson:"text" form:"text" binding:"required"`
}

struct for dbquery results mgo requires the string literal tags

func (Entry) Validate

func (e Entry) Validate(errors binding.Errors, req *http.Request) binding.Errors

type MgoBlog

type MgoBlog struct {
	// contains filtered or unexported fields
}

func (MgoBlog) Delete

func (b MgoBlog) Delete(id string) error

func (MgoBlog) FindById

func (b MgoBlog) FindById(id string) (e *Entry, err error)

func (MgoBlog) LatestEntries

func (b MgoBlog) LatestEntries() (entries []*Entry, err error)

LatestEntries loads all Blogentries in the results slice (sorted descending by date)

func (MgoBlog) Save

func (b MgoBlog) Save(e *Entry) error

type Options

type Options struct {
	DbName         string
	CollectionName string
}

Jump to

Keyboard shortcuts

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