services

package
v0.0.0-...-97c6c0c Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2022 License: MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// 广告区域
	ZONEINDEXSLICE  uint8 = iota + 1 // pc首页轮播
	ZONEINDEXBANNER                  // pc首页banner图
	ZONEMINDEX                       // h5首页轮播
	ZONENOV                          // 小说详情页右侧轮播
)
View Source
const (
	CRAWLER_WAIT uint8 = iota
	CRAWLER_RUNING

	MAX_BLOOM_SIZE = 10000000
	BLOOM_RATE     = 0.00001
)
View Source
const (
	NO_PROXY int = iota
	HTTP_PROXY
	IP_AUTO_PROXY

	STATE_WAIT int = iota
	STATE_RUNING
)

代理模式

View Source
const (
	TASKWAIT = iota
	TASKRUNING
	TASKFINISH
	TASKWAITGC

	// gc运行时间间隔(分钟)
	GCRUNTIME = 10

	// 每次gc运行查找的数量
	GCNUM = 100

	// 执行间隔时间
	INTERVAL_PERIOD time.Duration = 24 * time.Hour

	// 每天执行自动获取新小说时间
	HOUR_TO_TICK   int = 02
	MINUTE_TO_TICK int = 03
	SECOND_TO_TICK int = 05
)

Variables

View Source
var (
	ErrInvalidURL     = errors.New("非法URL")
	ErrNotCurrSiteURL = errors.New("非当前站点URL")
)
View Source
var (
	RoleService       *Role
	GroupService      *Group
	AdminService      *Admin
	AdminLogService   *AdminLog
	NovelService      *Novel
	CateService       *Cate
	ChapterService    *Chapter
	FeedbackService   *Feedback
	SnatchService     *Snatch
	BannerService     *Banner
	CrawlerService    *Crawler
	ProxyService      *Proxy
	ConfigService     *Config
	SearchService     *Search
	SearchLogService  *SearchLog
	SnatchRuleService *SnatchRule
)
View Source
var (
	ErrNotProvider    = errors.New("没有获取到采集点")
	ErrURLSnatchMatch = errors.New("该小说URL匹配不到采集站点")
)
View Source
var (
	ErrNovExists = errors.New("小说已经存在")
	ErrNovsEmpty = errors.New("获取到的小说为空")
)
View Source
var (
	ERRVALIDZONE = errors.New("广告区域不存在")
)

Functions

func DownImg

func DownImg(rawurl string) (string, error)

下载缩略图

func Init

func Init()

Types

type Admin

type Admin struct {
}

定义AdminService

func NewAdmin

func NewAdmin() *Admin

func (*Admin) Delete

func (this *Admin) Delete(id uint32) error

删除管理员

func (*Admin) Get

func (this *Admin) Get(id uint32) *models.Admin

获取单个管理员信息

func (*Admin) GetAll

func (this *Admin) GetAll() []*models.Admin

批量获取管理员列表

func (*Admin) GetMenus

func (this *Admin) GetMenus(adminId uint32) []*models.Role

获取当前管理员的菜单列表

func (*Admin) IsAccountExists

func (this *Admin) IsAccountExists(account string, filterId ...uint32) bool

判断管理员是否存在

func (*Admin) Login

func (this *Admin) Login(account, password string) (*models.Admin, error)

登录账号密码检测

func (*Admin) Save

func (this *Admin) Save(admin *models.Admin) error

添加/修改

func (*Admin) UpdateLoginInfo

func (this *Admin) UpdateLoginInfo(admin *models.Admin) error

修改用户登录信息

func (*Admin) UpdatePwd

func (this *Admin) UpdatePwd(admin *models.Admin) error

修改密码

func (*Admin) ValidPurview

func (this *Admin) ValidPurview(adminId uint32, module, action string) bool

验证用户是否有接口权限

type AdminLog

type AdminLog struct {
}

定义AdminLogService

func NewAdminLog

func NewAdminLog() *AdminLog

func (*AdminLog) Add

func (this *AdminLog) Add(a *models.AdminLog) error

添加操作日记

func (*AdminLog) Delete

func (this *AdminLog) Delete(id uint32) error

删除操作日记

func (*AdminLog) DeleteBatch

func (this *AdminLog) DeleteBatch(ids []string) error

批量删除操作日记

func (*AdminLog) Get

func (this *AdminLog) Get(id uint32) *models.AdminLog

获取单个操作日记信息

func (*AdminLog) GetAll

func (this *AdminLog) GetAll(args models.ArgsAdminLog) ([]*models.AdminLog, int64)

批量获取操作日记列表

type Banner struct {
}

定义BannerService

func NewBanner

func NewBanner() *Banner

func (*Banner) Delete

func (this *Banner) Delete(id uint32) error

删除banner

func (*Banner) DeleteBatch

func (this *Banner) DeleteBatch(ids []string) error

批量删除banner

func (*Banner) Get

func (this *Banner) Get(id uint32) *models.Banner

获取单个banner信息

func (*Banner) GetAll

func (this *Banner) GetAll(args map[string]interface{}) []*models.Banner

批量获取banner列表

func (*Banner) Save

func (this *Banner) Save(banner *models.Banner) error

添加/修改

func (Banner) Zones

func (this Banner) Zones() map[uint8]string

广告区域列表

type Cate

type Cate struct {
}

定义CateService

func NewCate

func NewCate() *Cate

func (*Cate) Delete

func (this *Cate) Delete(id uint32) error

删除小说分类

func (*Cate) DeleteBatch

func (this *Cate) DeleteBatch(ids []string) error

批量删除小说分类

func (*Cate) Get

func (this *Cate) Get(id uint32) *models.Cate

获取单个分类信息

func (*Cate) GetAll

func (this *Cate) GetAll() []*models.Cate

批量获取小说分类列表

func (*Cate) Save

func (this *Cate) Save(cate *models.Cate) error

添加/修改

type Chapter

type Chapter struct{}

func NewChapter

func NewChapter() *Chapter

func (*Chapter) DelByNovId

func (this *Chapter) DelByNovId(novId uint32) error

清空指定小说章节

func (*Chapter) Delete

func (this *Chapter) Delete(id uint64, novId uint32) error

删除操作章节

func (*Chapter) DeleteBatch

func (this *Chapter) DeleteBatch(novId uint32, ids []string) error

批量删除小说章节

func (*Chapter) Get

func (this *Chapter) Get(id uint64, novId uint32) *models.Chapter

获取单个章节内容

func (*Chapter) GetEmptyChaps

func (this *Chapter) GetEmptyChaps(novId uint32) []*models.Chapter

获取小说空章节列表

func (*Chapter) GetFirst

func (this *Chapter) GetFirst(novId uint32) *models.Chapter

获取第一章节

func (*Chapter) GetLast

func (this *Chapter) GetLast(novId uint32) *models.Chapter

获取小说最新章节

func (*Chapter) GetNext

func (this *Chapter) GetNext(novId, chapNo uint32) *models.Chapter

获取小说下一章节

func (*Chapter) GetNovChaps

func (this *Chapter) GetNovChaps(novId uint32, size, offset int, sort string, isCount bool) ([]*models.Chapter, int64)

获取小说章节列表

func (*Chapter) GetPre

func (this *Chapter) GetPre(novId, chapNo uint32) *models.Chapter

获取小说上一章节

func (*Chapter) InsertMulti

func (this *Chapter) InsertMulti(chapters []*models.Chapter, isInit bool) error

批量插入多个章节内容

func (*Chapter) Save

func (this *Chapter) Save(chapter *models.Chapter) error

添加编辑小说章节内容

func (*Chapter) UpdateEmpty

func (this *Chapter) UpdateEmpty(chapter *models.Chapter) error

更新空章节信息

func (*Chapter) UpdateViews

func (this *Chapter) UpdateViews(chapter *models.Chapter) error

章节浏览次数累加

type Config

type Config struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewConfig

func NewConfig() *Config

func (*Config) Bool

func (this *Config) Bool(key string, def ...bool) bool

func (*Config) GetAll

func (this *Config) GetAll() map[string]string

获取所有配置

func (*Config) Init

func (this *Config) Init()

func (*Config) Int

func (this *Config) Int(key string, def ...int) int

func (*Config) Int64

func (this *Config) Int64(key string, def ...int64) int64

func (*Config) Set

func (this *Config) Set(key string, value string) error

更新配置

func (*Config) String

func (this *Config) String(key string, def ...string) string

type Crawler

type Crawler struct {

	// 采集URL列表
	URLs *bloom.BloomFilter
	// contains filtered or unexported fields
}

定义CrawlerService

func NewCrawler

func NewCrawler() *Crawler

func (*Crawler) Init

func (this *Crawler) Init(provideName string) (*Crawler, error)

爬虫初始化

func (*Crawler) NewHtml

func (this *Crawler) NewHtml(rawurl string) (*goquery.Document, error)

网页请求 返回goquery格式内容

func (*Crawler) Run

func (this *Crawler) Run()

爬虫入口

type Feedback

type Feedback struct {
}

定义FeedbackService

func NewFeedback

func NewFeedback() *Feedback

func (*Feedback) Delete

func (this *Feedback) Delete(id uint32) error

删除反馈内容

func (*Feedback) DeleteBatch

func (this *Feedback) DeleteBatch(ids []string) error

批量删除反馈内容

func (*Feedback) Get

func (this *Feedback) Get(id uint32) *models.Feedback

获取单个反馈信息

func (*Feedback) GetAll

func (this *Feedback) GetAll(size, offset int, args map[string]interface{}) ([]*models.Feedback, int64)

批量获取反馈列表

func (*Feedback) Save

func (this *Feedback) Save(feed *models.Feedback) error

添加/修改

type Group

type Group struct{}

定义GroupService

func NewGroup

func NewGroup() *Group

func (*Group) Delete

func (this *Group) Delete(id uint32) error

删除群组

func (*Group) Get

func (this *Group) Get(id uint32) *models.Group

获取单个群组

func (*Group) GetAll

func (this *Group) GetAll() []*models.Group

批量获取群组

func (*Group) GetMenus

func (this *Group) GetMenus(groupId uint32) []*models.Role

获取当前权限组菜单列表

func (*Group) Save

func (this *Group) Save(group *models.Group) error

添加菜单/权限

func (*Group) ValidPurview

func (this *Group) ValidPurview(groupId uint32, module, action string) bool

验证该权限组是否有接口权限

type Novel

type Novel struct {
}

定义NovelService

func NewNovel

func NewNovel() *Novel
func (this *Novel) AddLink(novId uint32, link, source, chapterLink string) error

添加小说采集站点

func (*Novel) DelChapters

func (this *Novel) DelChapters(id uint32) error

清空小说章节列表

func (this *Novel) DelLink(id uint32) error

删除小说采集站点

func (*Novel) Delete

func (this *Novel) Delete(id uint32) error

删除小说

func (*Novel) DeleteBatch

func (this *Novel) DeleteBatch(ids []string) error

批量删除小说

func (*Novel) Get

func (this *Novel) Get(id uint32) *models.Novel

获取单个管理员信息

func (*Novel) GetAll

func (this *Novel) GetAll(args models.ArgsNovelList) ([]*models.Novel, int64)

批量获取小说列表

func (this *Novel) GetByLink(link, source string) *models.NovelLinks

根据你URL 和 站点获取小说采集URL

func (*Novel) GetByName

func (this *Novel) GetByName(name string) *models.Novel

判断小说是否存在

func (*Novel) GetCateRanks

func (this *Novel) GetCateRanks(cateId, size, offset int) []*models.Novel

获取同类推荐排行榜

func (*Novel) GetCollects

func (this *Novel) GetCollects(size, offset int) []*models.Novel

获取收藏榜列表

func (*Novel) GetEnds

func (this *Novel) GetEnds(size, offset int) []*models.Novel

获取完本小说列表

func (*Novel) GetHots

func (this *Novel) GetHots(size, offset int) []*models.Novel

获取热门小说

func (this *Novel) GetLinks(novId uint32) []*models.NovelLinks

获取小说采集站点列表

func (*Novel) GetList

func (this *Novel) GetList(size, offset int, qs map[string]interface{}) ([]*models.Novel, int64)

批量获取小说列表 用于前台查询

func (*Novel) GetNewUps

func (this *Novel) GetNewUps(size, offset int) []*models.Novel

获取最新更新小说列表

func (*Novel) GetNews

func (this *Novel) GetNews(size, offset int) []*models.Novel

获取新增小说榜单

func (*Novel) GetOriginals

func (this *Novel) GetOriginals(size, offset int) []*models.Novel

获取原创小说

func (*Novel) GetRanks

func (this *Novel) GetRanks(size, offset int) []*models.Novel

获取排行榜小说列表

func (*Novel) GetRecs

func (this *Novel) GetRecs(size, offset int) []*models.Novel

获取推荐小说

func (*Novel) GetSignNewBooks

func (this *Novel) GetSignNewBooks(size, offset int) []*models.Novel

获取新人签约榜列表

func (*Novel) GetTodayRecs

func (this *Novel) GetTodayRecs(size, offset int) []*models.Novel

获取今日推荐

func (*Novel) GetVipRecs

func (this *Novel) GetVipRecs(size, offset int) []*models.Novel

获取精品推荐小说

func (*Novel) GetVipRewards

func (this *Novel) GetVipRewards(size, offset int) []*models.Novel

获取VIP打赏

func (*Novel) GetVipUps

func (this *Novel) GetVipUps(size, offset int) []*models.Novel

获取VIP更新

func (*Novel) IsExists

func (this *Novel) IsExists(name string) bool

判断小说是否存在

func (*Novel) Save

func (this *Novel) Save(novel *models.Novel) error

添加/修改

func (*Novel) UpChapterInfo

func (this *Novel) UpChapterInfo(novId uint32, novTextNum, chapterNum int, chapterId uint64, chapterTitle string, status uint8) error

修改章节信息

func (*Novel) UpChapterTextNum

func (this *Novel) UpChapterTextNum(novId uint32, novTextNum int, isAdded bool) error

修改小说文字数

func (*Novel) UpNovelInfo

func (this *Novel) UpNovelInfo(nov *models.Novel) error

修改小说简介信息

func (*Novel) UpRecBatch

func (this *Novel) UpRecBatch(field string, books []string) error

批量更新推荐

func (*Novel) UpStatus

func (this *Novel) UpStatus(novId uint32, status uint8) error

更新小说连载状态

func (*Novel) UpViews

func (this *Novel) UpViews(novId uint32)

更新浏览次数

type Proxy

type Proxy struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

定义CrawlerService

func NewProxy

func NewProxy() *Proxy

func (*Proxy) Count

func (this *Proxy) Count() int

获取可用IP数量

func (*Proxy) Del

func (this *Proxy) Del(ip string) error

删除IP

func (*Proxy) Get

func (this *Proxy) Get() string

随机获取一个代理IP

func (*Proxy) GetAll

func (this *Proxy) GetAll() []string

获取所有IP

func (*Proxy) Init

func (this *Proxy) Init()

运行入口

type Role

type Role struct{}

func NewRole

func NewRole() *Role

func (*Role) GetMenus

func (this *Role) GetMenus(roleIds []string) []*models.Role

获取菜单分类

func (*Role) GetRole

func (this *Role) GetRole(id uint32) *models.Role

获取单个权限

func (*Role) GetRoles

func (this *Role) GetRoles(isTree ...bool) []*models.Role

获取权限分类

func (*Role) Save

func (this *Role) Save(role *models.Role) error

添加菜单/权限

func (*Role) ValidPurview

func (this *Role) ValidPurview(groupId uint32, module, action string, roleIds []string) bool

检查是否有权限

type Search struct {
}

定义SearchService

func NewSerach

func NewSerach() *Search

func (*Search) Delete

func (this *Search) Delete(id uint64) error

删除搜索记录

func (*Search) DeleteBatch

func (this *Search) DeleteBatch(ids []string) error

批量删除搜索记录

func (*Search) GetAll

func (this *Search) GetAll(args models.ArgsSearchList) ([]*models.Search, int64)

获取搜索记录列表

func (*Search) GetRes

func (this *Search) GetRes(size int) []*models.Search

获取推荐的搜索关键字

func (*Search) InsertOrIncrement

func (this *Search) InsertOrIncrement(kw string, log *models.SearchLog) error

添加搜索记录

func (*Search) UpRec

func (this *Search) UpRec(id uint64, isRec uint8) error

设置推荐/取消推荐

type SearchLog

type SearchLog struct {
}

定义SearchLogService

func NewSearchLog

func NewSearchLog() *SearchLog

func (*SearchLog) Add

func (this *SearchLog) Add(a *models.SearchLog) error

添加搜索日记

func (*SearchLog) Delete

func (this *SearchLog) Delete(id uint64) error

删除操作日记

func (*SearchLog) DeleteBatch

func (this *SearchLog) DeleteBatch(ids []string) error

批量删除搜索日记

func (*SearchLog) GetAll

func (this *SearchLog) GetAll(args models.ArgsSearchLogList) ([]*models.SearchLog, int64)

获取搜索日记列表

type Snatch

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

func NewSnatch

func NewSnatch() *Snatch

func (*Snatch) FindNovel

func (this *Snatch) FindNovel(source, kw string) (*snatchs.SnatchInfo, error)

查找小说

func (*Snatch) FindNovels

func (this *Snatch) FindNovels(kw string) []*snatchs.SnatchInfo

查找小说列表

func (*Snatch) GetChapter

func (this *Snatch) GetChapter(source, rawurl string) (*snatchs.SnatchInfo, error)

获取小说章节内容

func (*Snatch) GetChapters

func (this *Snatch) GetChapters(source, rawurl string) ([]*snatchs.SnatchInfo, error)

获取小说章节列表

func (*Snatch) GetNovel

func (this *Snatch) GetNovel(source, rawurl string) (*snatchs.SnatchInfo, error)

获取一本小说

func (*Snatch) GetProvideByURL

func (this *Snatch) GetProvideByURL(url string) (*models.SnatchRule, error)

根据URL匹配采集站点

func (*Snatch) InitNovel

func (this *Snatch) InitNovel(url string) error

初始化一本小说 采集小说入库

func (*Snatch) IsBookURL

func (this *Snatch) IsBookURL(source, rawurl string) bool

是否小说简介页面

func (*Snatch) IsCrawlerURL

func (this *Snatch) IsCrawlerURL(source, rawurl string) bool

是否小说是否爬虫页面

func (*Snatch) SnatchNovel

func (this *Snatch) SnatchNovel(novId uint32) error

执行指定小说的采集任务

type SnatchRank

type SnatchRank struct{}

func NewSnatchRank

func NewSnatchRank() *SnatchRank

func (*SnatchRank) NewHtml

func (this *SnatchRank) NewHtml(rawurl, charset string) (*goquery.Document, error)

网页请求 返回goquery格式内容

func (*SnatchRank) Qidian

func (this *SnatchRank) Qidian()

采集起点排行榜

func (*SnatchRank) Run

func (this *SnatchRank) Run()

运行

type SnatchRule

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

定义SnatchRuleService

func NewSnatchRule

func NewSnatchRule() *SnatchRule

func (*SnatchRule) Delete

func (this *SnatchRule) Delete(id uint32) error

删除采集规则

func (*SnatchRule) DeleteBatch

func (this *SnatchRule) DeleteBatch(ids []string) error

批量删除采集规则

func (*SnatchRule) Get

func (this *SnatchRule) Get(id uint32) *models.SnatchRule

获取单个采集配置

func (*SnatchRule) GetAll

func (this *SnatchRule) GetAll(args *models.ArgsListRule) []*models.SnatchRule

获取采集规则列表

func (*SnatchRule) GetByCode

func (this *SnatchRule) GetByCode(code string) *models.SnatchRule

获取单个采集配置

func (*SnatchRule) GetSnatchs

func (this *SnatchRule) GetSnatchs() map[string]*models.SnatchRule

获取可用采集器列表

func (*SnatchRule) Init

func (this *SnatchRule) Init()

func (*SnatchRule) Load

func (this *SnatchRule) Load()

func (*SnatchRule) Save

func (this *SnatchRule) Save(sr *models.SnatchRule) error

添加/修改

func (*SnatchRule) UpState

func (this *SnatchRule) UpState(id uint32, state uint8) error

启用/禁用

type SnatchTask

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

func NewSnatchTask

func NewSnatchTask(novId uint32) *SnatchTask

func (*SnatchTask) IsGc

func (this *SnatchTask) IsGc() bool

是否可以被gc回收

func (*SnatchTask) Run

func (this *SnatchTask) Run()

type SnatchTaskManager

type SnatchTaskManager struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

采集任务管理

func NewSnatchTaskManager

func NewSnatchTaskManager() *SnatchTaskManager

func (*SnatchTaskManager) AddTask

func (this *SnatchTaskManager) AddTask(novId uint32) error

添加采集章节更新队列

func (*SnatchTaskManager) DelTask

func (this *SnatchTaskManager) DelTask(novId uint32) error

删除采集队列任务

func (*SnatchTaskManager) LoadNovels

func (this *SnatchTaskManager) LoadNovels() int

加载小说写入任务队列

func (*SnatchTaskManager) Run

func (this *SnatchTaskManager) Run()

获取章节小说更新

func (*SnatchTaskManager) RunOneTask

func (this *SnatchTaskManager) RunOneTask(novId uint32) error

运行指定小说的采集任务

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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