repository

package module
v0.0.0-...-747e3eb Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2016 License: MIT Imports: 6 Imported by: 2

README

repository

Build Status

接口化的数据仓库,默认实现了Mysql,你可以实现自己的数据仓库并注册进来(Postgresql等)

  • 定义顶层数据操作接口
  • 实现默认数据仓库(Mysql)

Mysql表结构

  • torrent0 ~ torrentf 分表存储metadata
  • history 存储搜索历史
  • infohash 存储爬虫抓取到的活跃infohash
  • recommend 存储网站首页显示的推荐关键词

初始化

  • 创建名为 torrent的库
  • 执行mysql.sql中的sql语句

安装

go get github.com/btlike/repository

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound = errors.New("not found")
)

定义通用变量

Functions

This section is empty.

Types

type File

type File struct {
	Name   string
	Length int64
}

File 定义了资源中包含的文件

type MysqlRepo

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

MysqlRepo 实现基于mysql的数据仓库

func NewMysqlRepository

func NewMysqlRepository(conn string, maxIdleConns int, maxOpenConns int) (repo *MysqlRepo, err error)

NewMysqlRepository 新建mysql数据仓库

func (*MysqlRepo) BatchDeleteInfohash

func (p *MysqlRepo) BatchDeleteInfohash(infohash []string) (err error)

BatchDeleteInfohash 批量删除infohash

func (*MysqlRepo) BatchGetInfohash

func (p *MysqlRepo) BatchGetInfohash(limit int64) (is []string, err error)

BatchGetInfohash 批量获取infohash

func (*MysqlRepo) BatchGetTorrentByInfohash

func (p *MysqlRepo) BatchGetTorrentByInfohash(infohash []string) (ts []Torrent, err error)

BatchGetTorrentByInfohash 通过infohash批量查询资源

func (*MysqlRepo) CreateHistory

func (p *MysqlRepo) CreateHistory(keyword, source string) (err error)

CreateHistory 增加搜索历史

func (*MysqlRepo) CreateInfohash

func (p *MysqlRepo) CreateInfohash(hash string) (err error)

CreateInfohash 增加infohash

func (*MysqlRepo) CreateTorrent

func (p *MysqlRepo) CreateTorrent(t Torrent) (err error)

CreateTorrent 增加资源

func (*MysqlRepo) GetRecommend

func (p *MysqlRepo) GetRecommend() (name []string, err error)

GetRecommend 获取推荐列表

func (*MysqlRepo) GetTorrentByInfohash

func (p *MysqlRepo) GetTorrentByInfohash(infohash string) (t Torrent, err error)

GetTorrentByInfohash 通过infohash查询资源

type Repository

type Repository interface {
	//Torrent
	GetTorrentByInfohash(infohash string) (torrent Torrent, err error)
	BatchGetTorrentByInfohash(infohash []string) (torrent []Torrent, err error)
	CreateTorrent(torrent Torrent) (err error)

	//Infohash
	BatchGetInfohash(limit int64) (infohash []string, err error)
	BatchDeleteInfohash(infohash []string) (err error)
	CreateInfohash(infohash string) (err error)

	//recommend
	GetRecommend() (name []string, err error)

	//history
	CreateHistory(keyword, source string) (err error)
}

Repository 定义了数据仓库需要实现的接口

type Torrent

type Torrent struct {
	Infohash   string
	Name       string
	Length     int64
	Heat       int64
	FileCount  int64
	Files      []File
	CreateTime time.Time
}

Torrent 定义了资源详细信息

Jump to

Keyboard shortcuts

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