34 lines
461 B
Go
34 lines
461 B
Go
package models
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/jinzhu/gorm"
|
|
)
|
|
|
|
//Post model
|
|
type Post struct {
|
|
gorm.Model
|
|
Title string
|
|
Author string
|
|
Published time.Time
|
|
LastEdited time.Time
|
|
Content []byte
|
|
}
|
|
|
|
//Create new post
|
|
func (p Post) Create() error {
|
|
return create(&p)
|
|
}
|
|
|
|
func (p *Post) Read() (*Post, error) {
|
|
err := read(&p)
|
|
return p, err
|
|
}
|
|
|
|
func (p Post) ReadAll() ([]Post, error) {
|
|
var posts []Post
|
|
err := readAll(&posts)
|
|
return posts, err
|
|
}
|