Documentation
¶
Index ¶
- Constants
- Variables
- type APIClient
- func (c *APIClient) AddArticle(tags []string, data string, ttl int64, ...) (uint64, string, string, error)
- func (c *APIClient) AddModel(modelName, modelDescription string) error
- func (c *APIClient) DeleteArticle(articleId uint64, customArticleId, customArticleIdEx string) error
- func (c *APIClient) DeleteModel(modelName string) error
- func (c *APIClient) GetAllModels() (map[string]string, error)
- func (c *APIClient) GetArticle(articleId uint64, customArticleId, customArticleIdEx string) (*RemoteArticle, error)
- func (c *APIClient) GetArticleCount() uint64
- func (c *APIClient) GetArticleCountByTag(tagName string) uint64
- func (c *APIClient) GetMaxArticleId() uint64
- func (c *APIClient) GetModelInfo() (uint64, uint64, uint64, error)
- func (c *APIClient) GetNextArticles(articleId uint64, customArticleId, customArticleIdEx string, n int) []*RemoteArticle
- func (c *APIClient) GetNextArticlesByTag(tagName string, articleId uint64, customArticleId, customArticleIdEx string, ...) []*RemoteArticle
- func (c *APIClient) GetNextTags(tagName string, n int) []*RemoteTag
- func (c *APIClient) GetPrevArticles(articleId uint64, customArticleId, customArticleIdEx string, n int) []*RemoteArticle
- func (c *APIClient) GetPrevArticlesByTag(tagName string, articleId uint64, customArticleId, customArticleIdEx string, ...) []*RemoteArticle
- func (c *APIClient) GetPrevTags(tagName string, n int) []*RemoteTag
- func (c *APIClient) GetTagById(id uint64) (*RemoteTag, error)
- func (c *APIClient) GetTagByName(name string) (*RemoteTag, error)
- func (c *APIClient) GetTagCount() uint64
- func (c *APIClient) RenameTag(oldName, newName string) error
- func (c *APIClient) Start(remoteAddr, modelName string)
- func (c *APIClient) UpdateArticle(articleId uint64, customArticleId, customArticleIdEx string, newTags []string, ...) error
- type APIServer
- type APIServerConfig
- type AddArticleReq
- type AddArticleResp
- type AddModelResp
- type BaseResp
- type DeleteArticleReq
- type DeleteArticleResp
- type DeleteModelResp
- type GetAllModelsResp
- type GetArticleCountByTagReq
- type GetArticleCountByTagResp
- type GetArticleReq
- type GetArticleResp
- type GetModelInfoResp
- type GetNextArticlesByTagReq
- type GetNextArticlesByTagResp
- type GetNextArticlesReq
- type GetNextArticlesResp
- type GetNextTagsReq
- type GetNextTagsResp
- type GetPrevArticlesByTagReq
- type GetPrevArticlesByTagResp
- type GetPrevArticlesReq
- type GetPrevArticlesResp
- type GetPrevTagsReq
- type GetPrevTagsResp
- type GetTagByIdReq
- type GetTagByIdResp
- type GetTagByNameReq
- type GetTagByNameResp
- type ModelConfig
- type ModelMgr
- func (m *ModelMgr) AddModel(name, description string) error
- func (m *ModelMgr) CheckExist(name string) bool
- func (m *ModelMgr) GetAllModels() map[string]string
- func (m *ModelMgr) GetModelDir(modelName string) string
- func (m *ModelMgr) RemoveModel(name string) error
- func (m *ModelMgr) WriteToFile() error
- type RemoteArticle
- type RemoteTag
- type RenameTagReq
- type RenameTagResp
- type UpdateArticleReq
- type UpdateArticleResp
Constants ¶
View Source
const ( // model管理,比如:/model/api APIGetAllModels = "/get-all-models" APIAddModel = "/add" APIDeleteModel = "/delete" // 针对指定model的访问,比如:/admin/model-name/api APIGetModelInfo = "/get-model-info" APIAddArticle = "/add-article" APIDeleteArticle = "/delete-article" APIGetArticle = "/get-article" APIGetNextArticles = "/get-next-articles" APIGetPrevArticles = "/get-prev-articles" APIGetNextArticlesByTag = "/get-next-articles-by-tag" APIGetPrevArticlesByTag = "/get-prev-articles-by-tag" APIUpdateArticle = "/update-article" APIGetTagById = "/get-tag-by-id" APIGetTagByName = "/get-tag-by-name" APIGetNextTags = "/get-next-tags" APIGetPrevTags = "/get-prev-tags" APIRenameTag = "/rename-tag" APIGetArticleCountByTag = "/get-article-count-by-tag" )
View Source
const ( ErrCodeSuccess = 0 ErrCodeFailed = -1 ErrCodeArticleDeleted = -2 ErrMsgSuccess = "success" ErrModeExist = "model exist" ErrModelNotExist = "model not exist" ErrModelNameIsNull = "model name is null" ErrMsgArticleDeleted = "article is deleted" )
View Source
const ( // 数据库名称 ArticleDBPath = "article.db" TagDBPath = "tag.db" IndexDBPath = "index.db" TTLDBPath = "ttl.db" // model中的文章ID都是uint64类型,需要增加字符串ID的扩展功能 // 保存字符串ID和整型ID的映射,也可以用于自定义ID(字符串) // 如果不使用自定义ID,则随机产生一个字符串ID // 这样做的原因避免ID为整数,然后导致网站被遍历抓取 // 用自定义ID还有一个好处,比如将文章的标题作为文章的自定义ID,自带去重效果 IdDBPath = "id.db" // 额外扩展一个自定义ID,业务层设置,不自动生成 CustomIdDBPath = "custom_id.db" )
Variables ¶
View Source
var ( // 注意:错误分为两类,获取文章时需要区分 // 1. 文章不存在,这里有两种情况: // 1.1 如果文章是被删除的(包括过期自动删除),返回 ErrArticleDeleted // 1.2 如果文章从未存在过,返回 ErrNotFound // 2. 服务器连接失败或者错误,返回500 ErrServerFailed = errors.New("500 server error") ErrNotFound = errors.New("404 not found") ErrArticleDeleted = errors.New("article is deleted") )
Functions ¶
This section is empty.
Types ¶
type APIClient ¶
type APIClient struct {
// contains filtered or unexported fields
}
func (*APIClient) AddArticle ¶
func (c *APIClient) AddArticle(tags []string, data string, ttl int64, customArticleId, customArticleIdEx string) (uint64, string, string, error)
customArticleId 可以为空,如果为空,则服务器自动生成 customArticleIdEx 可以为空,服务器不会自动生成 返回:文章ID、自定义文章ID、扩展自定义文章ID
func (*APIClient) DeleteArticle ¶
func (c *APIClient) DeleteArticle(articleId uint64, customArticleId, customArticleIdEx string) error
文章ID随便填一个,customArticleId 优先
func (*APIClient) DeleteModel ¶
func (*APIClient) GetArticle ¶
func (c *APIClient) GetArticle(articleId uint64, customArticleId, customArticleIdEx string) (*RemoteArticle, error)
func (*APIClient) GetArticleCount ¶
func (*APIClient) GetArticleCountByTag ¶
func (*APIClient) GetMaxArticleId ¶
func (*APIClient) GetModelInfo ¶
返回文章数量、分类数量、最大的文章ID
func (*APIClient) GetNextArticles ¶
func (c *APIClient) GetNextArticles(articleId uint64, customArticleId, customArticleIdEx string, n int) []*RemoteArticle
func (*APIClient) GetNextArticlesByTag ¶
func (*APIClient) GetPrevArticles ¶
func (c *APIClient) GetPrevArticles(articleId uint64, customArticleId, customArticleIdEx string, n int) []*RemoteArticle
func (*APIClient) GetPrevArticlesByTag ¶
func (*APIClient) GetTagCount ¶
type APIServer ¶
type APIServer struct {
// contains filtered or unexported fields
}
func (*APIServer) Start ¶
func (s *APIServer) Start(config *APIServerConfig)
type APIServerConfig ¶
type AddArticleReq ¶
type AddArticleResp ¶
type AddModelResp ¶
type AddModelResp = BaseResp
type DeleteArticleReq ¶
type DeleteArticleResp ¶
type DeleteArticleResp = BaseResp
type DeleteModelResp ¶
type DeleteModelResp = BaseResp
type GetAllModelsResp ¶
type GetArticleCountByTagReq ¶
type GetArticleCountByTagReq struct {
TagName string `json:"tag_name"`
}
type GetArticleReq ¶
type GetArticleReq = DeleteArticleReq
type GetArticleResp ¶
type GetArticleResp struct { BaseResp *RemoteArticle }
type GetModelInfoResp ¶
type GetNextArticlesByTagReq ¶
type GetNextArticlesByTagReq struct { GetNextArticlesReq Tag string `json:"tag"` }
type GetNextArticlesByTagResp ¶
type GetNextArticlesByTagResp = GetNextArticlesResp
type GetNextArticlesReq ¶
type GetNextArticlesResp ¶
type GetNextArticlesResp struct { BaseResp RemoteArticles []*RemoteArticle `json:"remote_articles"` }
type GetNextTagsReq ¶
type GetNextTagsResp ¶
type GetPrevArticlesByTagReq ¶
type GetPrevArticlesByTagReq = GetNextArticlesByTagReq
type GetPrevArticlesByTagResp ¶
type GetPrevArticlesByTagResp = GetNextArticlesByTagResp
type GetPrevArticlesReq ¶
type GetPrevArticlesReq = GetNextArticlesReq
type GetPrevArticlesResp ¶
type GetPrevArticlesResp = GetNextArticlesResp
type GetPrevTagsReq ¶
type GetPrevTagsReq = GetNextTagsReq
type GetPrevTagsResp ¶
type GetPrevTagsResp = GetNextTagsResp
type GetTagByIdReq ¶
type GetTagByIdReq struct {
TagId uint64 `json:"tag_id"`
}
type GetTagByIdResp ¶
type GetTagByNameReq ¶
type GetTagByNameReq struct {
TagName string `json:"tag_name"`
}
type GetTagByNameResp ¶
type GetTagByNameResp = GetTagByIdResp
type ModelConfig ¶
type ModelMgr ¶
type ModelMgr struct { // 数据存储目录 DataDir string // 配置文件路径 ConfPath string // 配置文件解析后的数据 Conf *ModelConfig }
func NewModelMgr ¶
confPath: 配置文件路径,比如:./model.conf dataDir: 数据存储目录,末尾带有 /
func (*ModelMgr) CheckExist ¶
func (*ModelMgr) GetAllModels ¶
func (*ModelMgr) GetModelDir ¶
func (*ModelMgr) RemoveModel ¶
func (*ModelMgr) WriteToFile ¶
type RemoteArticle ¶
type RemoteArticle struct { *gmodel.Article CustomArticleId string `json:"custom_article_id"` // 自定义文章ID,优先级高于 Article.Id CustomArticleIdEx string `json:"custom_article_id_ex"` // 自定义文章ID,优先级高于 Article.Id,但低于 CustomArticleId TagNameArray []string `json:"tag_name_array"` // 分类数组 }
CustomArticleId 优先,CustomArticleId为空时才使用 Article.Id,下同 注意:CustomArticleId 和 CustomArticleIdEx(如果存在)永不删除,且永远映射到 Article.Id, 即使 Article 被删除,这样可以避免生成重复的字符串ID,以及避免旧的字符串ID(对应文章已经删除)可以访问新的文章
type RenameTagReq ¶
type RenameTagResp ¶
type RenameTagResp = BaseResp
type UpdateArticleReq ¶
type UpdateArticleResp ¶
type UpdateArticleResp = BaseResp
Click to show internal directories.
Click to hide internal directories.