Documentation ¶
Index ¶
- Variables
- func InitCollections(db *mongo.Database) error
- type Article
- type ArticleDAO
- type AuthorDAO
- type GORMArticleDAO
- func (dao *GORMArticleDAO) GetByAuthor(ctx context.Context, author int64, offset, limit int) ([]Article, error)
- func (dao *GORMArticleDAO) GetById(ctx context.Context, id int64) (Article, error)
- func (dao *GORMArticleDAO) GetPubById(ctx context.Context, id int64) (PublishedArticle, error)
- func (dao *GORMArticleDAO) Insert(ctx context.Context, art Article) (int64, error)
- func (dao *GORMArticleDAO) Sync(ctx context.Context, art Article) (int64, error)
- func (dao *GORMArticleDAO) SyncClosure(ctx context.Context, art Article) (int64, error)
- func (dao *GORMArticleDAO) SyncStatus(ctx context.Context, author, id int64, status uint8) error
- func (dao *GORMArticleDAO) UpdateById(ctx context.Context, art Article) error
- type IDGenerator
- type MongoDBDAO
- func (m *MongoDBDAO) GetByAuthor(ctx context.Context, author int64, offset, limit int) ([]Article, error)
- func (m *MongoDBDAO) GetById(ctx context.Context, id int64) (Article, error)
- func (m *MongoDBDAO) GetPubById(ctx context.Context, id int64) (PublishedArticle, error)
- func (m *MongoDBDAO) Insert(ctx context.Context, art Article) (int64, error)
- func (m *MongoDBDAO) Sync(ctx context.Context, art Article) (int64, error)
- func (m *MongoDBDAO) SyncStatus(ctx context.Context, author, id int64, status uint8) error
- func (m *MongoDBDAO) UpdateById(ctx context.Context, art Article) error
- type PublishedArticle
- type PublishedArticleV1
- type ReaderDAO
- type S3DAO
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrPossibleIncorrectAuthor = errors.New("用户在尝试操作非本人数据")
Functions ¶
func InitCollections ¶
Types ¶
type Article ¶
type Article struct { Id int64 `gorm:"primaryKey,autoIncrement" bson:"id,omitempty"` // 标题的长度 // 正常都不会超过这个长度 Title string `gorm:"type=varchar(4096)" bson:"title,omitempty"` Content string `gorm:"type=BLOB" bson:"content,omitempty"` // 作者 AuthorId int64 `gorm:"index" bson:"author_id,omitempty"` Status uint8 `bson:"status,omitempty"` Ctime int64 `bson:"ctime,omitempty"` Utime int64 `bson:"utime,omitempty"` }
type ArticleDAO ¶
type ArticleDAO interface { Insert(ctx context.Context, art Article) (int64, error) UpdateById(ctx context.Context, art Article) error GetByAuthor(ctx context.Context, author int64, offset, limit int) ([]Article, error) GetById(ctx context.Context, id int64) (Article, error) GetPubById(ctx context.Context, id int64) (PublishedArticle, error) Sync(ctx context.Context, art Article) (int64, error) SyncStatus(ctx context.Context, author, id int64, status uint8) error }
func NewGORMArticleDAO ¶
func NewGORMArticleDAO(db *gorm.DB) ArticleDAO
func NewMongoDBDAO ¶
func NewMongoDBDAO(db *mongo.Database, node *snowflake.Node) ArticleDAO
func NewMongoDBDAOV1 ¶
func NewMongoDBDAOV1(db *mongo.Database, idGen IDGenerator) ArticleDAO
type AuthorDAO ¶
type AuthorDAO interface { Insert(ctx context.Context, art Article) (int64, error) UpdateById(ctx context.Context, article Article) error }
func NewAuthorDAO ¶
type GORMArticleDAO ¶
type GORMArticleDAO struct {
// contains filtered or unexported fields
}
func (*GORMArticleDAO) GetByAuthor ¶
func (*GORMArticleDAO) GetPubById ¶
func (dao *GORMArticleDAO) GetPubById(ctx context.Context, id int64) (PublishedArticle, error)
func (*GORMArticleDAO) SyncClosure ¶
func (*GORMArticleDAO) SyncStatus ¶
func (*GORMArticleDAO) UpdateById ¶
func (dao *GORMArticleDAO) UpdateById(ctx context.Context, art Article) error
UpdateById 只更新标题、内容和状态
type IDGenerator ¶
type IDGenerator func() int64
type MongoDBDAO ¶
type MongoDBDAO struct {
// contains filtered or unexported fields
}
func (*MongoDBDAO) GetByAuthor ¶
func (*MongoDBDAO) GetPubById ¶
func (m *MongoDBDAO) GetPubById(ctx context.Context, id int64) (PublishedArticle, error)
func (*MongoDBDAO) SyncStatus ¶
func (*MongoDBDAO) UpdateById ¶
func (m *MongoDBDAO) UpdateById(ctx context.Context, art Article) error
type PublishedArticleV1 ¶
type PublishedArticleV1 struct { Id int64 `gorm:"primaryKey,autoIncrement" bson:"id,omitempty"` Title string `gorm:"type=varchar(4096)" bson:"title,omitempty"` AuthorId int64 `gorm:"index" bson:"author_id,omitempty"` Status uint8 `bson:"status,omitempty"` Ctime int64 `bson:"ctime,omitempty"` Utime int64 `bson:"utime,omitempty"` }
type ReaderDAO ¶
type ReaderDAO interface { Upsert(ctx context.Context, art Article) error UpsertV2(ctx context.Context, art PublishedArticle) error }
func NewReaderDAO ¶
type S3DAO ¶
type S3DAO struct { // 通过组合 GORMArticleDAO 来简化操作 // 当然在实践中,你是不太会有组合的机会 // 你操作制作库总是一样的 // 你就是操作线上库的时候不一样 GORMArticleDAO // contains filtered or unexported fields }
Click to show internal directories.
Click to hide internal directories.