pinbook

package module
v0.0.0-...-fa578f2 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2015 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const PageSize = 6

Variables

This section is empty.

Functions

func ServeApp

func ServeApp(cfg *Config) error

Types

type App

type App struct {
	Cfg *Config
	DB  *Database
}

type Author

type Author struct {
	Id   bson.ObjectId `bson:"_id" json:"_id"`
	Name string        `json:"name"`
}

type Config

type Config struct {
	DbHost     string
	DbName     string
	SecretKey  string
	Port       int
	StaticDir  string
	UploadsDir string
}

type Context

type Context struct {
	*App
	User     *User
	Params   httprouter.Params
	Request  *http.Request
	Response http.ResponseWriter
}

func NewContext

func NewContext(app *App, w http.ResponseWriter, r *http.Request, ps httprouter.Params) *Context

func (*Context) DecodeJSON

func (c *Context) DecodeJSON(payload interface{}) error

func (*Context) Error

func (c *Context) Error(msg string, status int)

func (*Context) GetObjectId

func (c *Context) GetObjectId(name string) bson.ObjectId

func (*Context) GetSession

func (c *Context) GetSession() sessions.Session

func (*Context) GetUser

func (c *Context) GetUser() error

func (*Context) HandleError

func (c *Context) HandleError(err error)

func (*Context) JSON

func (c *Context) JSON(payload interface{}, status int) error

func (*Context) Login

func (c *Context) Login(user *User)

func (*Context) Logout

func (c *Context) Logout()

func (*Context) NotFound

func (c *Context) NotFound()

func (*Context) Query

func (c *Context) Query(name string) string

func (*Context) Redirect

func (c *Context) Redirect(url string)

func (*Context) Render

func (c *Context) Render(name string, ctx TemplateContext, status int) error

func (*Context) Status

func (c *Context) Status(status int)

func (*Context) String

func (c *Context) String(msg string, status int)

func (*Context) Validate

func (c *Context) Validate(v Validator) error

type Database

type Database struct {
	*mgo.Database
	Users *mgo.Collection
	Posts *mgo.Collection
}

func NewDatabase

func NewDatabase(db *mgo.Database) *Database

type ErrorMap

type ErrorMap struct {
	Errors map[string]string `json:"errors"`
}

func (*ErrorMap) Add

func (m *ErrorMap) Add(field string, msg string)

func (ErrorMap) Error

func (m ErrorMap) Error() string

func (*ErrorMap) IsEmpty

func (m *ErrorMap) IsEmpty() bool

type Pagination

type Pagination struct {
	Posts   []Post `json:"posts"`
	Total   int    `json:"total"`
	IsFirst bool   `json:"isFirst"`
	IsLast  bool   `json:"isLast"`
	Page    int    `json:"page"`
	Skip    int    `json:"-"`
}

func NewPagination

func NewPagination(page int, total int) *Pagination

type Post

type Post struct {
	Id       bson.ObjectId `bson:"_id" json:"_id"`
	Title    string        `json:"title"`
	URL      string        `json:"url"`
	Image    string        `json:"image"`
	Comment  string        `json:"comment"`
	Score    int64         `json:"score"`
	Created  time.Time     `json:"created"`
	AuthorId bson.ObjectId `bson:"author" json:"-"`
	Author   *Author       `bson:"-" json:"author"`
}

type TemplateContext

type TemplateContext map[string]interface{}

type User

type User struct {
	Id         bson.ObjectId   `bson:"_id" json:"_id"`
	Name       string          `json:"name"`
	Email      string          `json:"email"`
	Password   string          `json:"-"`
	TotalScore int64           `json:"totalScore"`
	Created    time.Time       `json:"created"`
	Votes      []bson.ObjectId `json:"votes"`
}

type Validator

type Validator interface {
	Validate(*Context, *ErrorMap) error
}

Directories

Path Synopsis
cmds

Jump to

Keyboard shortcuts

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