Documentation ¶
Index ¶
- Constants
- func ServeApp(cfg *Config) error
- type App
- type Author
- type Config
- type Context
- func (c *Context) DecodeJSON(payload interface{}) error
- func (c *Context) Error(msg string, status int)
- func (c *Context) GetObjectId(name string) bson.ObjectId
- func (c *Context) GetSession() sessions.Session
- func (c *Context) GetUser() error
- func (c *Context) HandleError(err error)
- func (c *Context) JSON(payload interface{}, status int) error
- func (c *Context) Login(user *User)
- func (c *Context) Logout()
- func (c *Context) NotFound()
- func (c *Context) Query(name string) string
- func (c *Context) Redirect(url string)
- func (c *Context) Render(name string, ctx TemplateContext, status int) error
- func (c *Context) Status(status int)
- func (c *Context) String(msg string, status int)
- func (c *Context) Validate(v Validator) error
- type Database
- type ErrorMap
- type Pagination
- type Post
- type TemplateContext
- type User
- type Validator
Constants ¶
View Source
const PageSize = 6
Variables ¶
This section is empty.
Functions ¶
Types ¶
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 (*Context) GetSession ¶
func (c *Context) GetSession() sessions.Session
func (*Context) HandleError ¶
type Database ¶
type Database struct { *mgo.Database Users *mgo.Collection Posts *mgo.Collection }
func NewDatabase ¶
func NewDatabase(db *mgo.Database) *Database
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{}
Click to show internal directories.
Click to hide internal directories.