Documentation ¶
Overview ¶
包含了数据接口返回数据的结构, 忽略了一些无用数据和未知字段
Index ¶
- Constants
- Variables
- func PostListRequest(tid string, pn int, rn int, withSubPost bool) *gen.Request
- func ThreadListRequest(kw string, pn int, rn int) *gen.Request
- type Content
- type Forum
- type Post
- type PostListResponse
- type RequestUser
- type ResponseStatus
- type SubPost
- type TextGenerator
- type Thread
- type ThreadListResponse
- type TiebaBool
- type TiebaTime
- type TiebaUInt
- type User
Constants ¶
const ( // 客户端类型 iOS = "1", android = "2" ClientType = "2" // 客户端版本 ClientVersion = "7.0.0" // 客户端子版本, 使用mini版参数能够减少一些无用信息 SubAppType = "mini" )
客户端信息, 不同的客户端信息相同参数下返回的数据并不相同
const MaxPostNum = 30
const MaxThreadNum = 100
Variables ¶
var DefaultRequest *gen.Request
默认的请求对象, 建立新请求对象时时调用其Clone方法, 不要直接修改此对象
var Logger = logrus.New()
Functions ¶
func PostListRequest ¶
获取帖子内容 tid 帖子ID pn 第几页 rn 每页最大条目数量, 2<=rn<=30 rn=0 Error 1989002: 加载数据失败 rn=1 Error 29: 这个楼层可能已被删除啦,去看看其他贴子吧 withSubPost 是否带上楼中楼
Types ¶
type Content ¶
type Content struct { Type string `json:"type"` Text string `json:"text,omitempty" bson:",omitempty"` Link string `json:"link,omitempty" bson:",omitempty"` C string `json:"c,omitempty" bson:",omitempty"` BSize string `json:"bsize,omitempty" bson:",omitempty"` ImgSrc string `json:"origin_src,omitempty" bson:"img_src,omitempty"` UID string `json:"uid,omitempty" bson:",omitempty"` VoiceMD5 string `json:"voice_md5,omitempty" bson:"voice_md5,omitempty"` DuringTime string `json:"during_time,omitempty" bson:"during_time,omitempty"` }
楼层和楼中楼内容 不同的类型有不同的内容 帖子一楼可能会有 is_native_app: string, native_app: list 两个字段 0 , 文字: text 1 , 超链接: link 2 , 表情: text, c 3 , 图片: text, bsize, size, origin_src, cdn_src, big_cdn_src 4 , @: text, uid 5 , 视频: e_type, width, height, bsize, during_time, origin_size, text, link, src, count 10, 语音: during_time, voice_md5, is_sub
func (Content) GenerateText ¶
type Forum ¶
type Forum struct { ID string `json:"id"` Name string `json:"name"` IsExists TiebaBool `json:"is_exists" bson:"is_exists"` // 实际请求时贴吧不存在返回的是 error_code, 这个可能是贴吧被屏蔽的标志? Avatar string `json:"avatar"` FirstClass string `json:"first_class" bson:"first_class"` SecondClass string `json:"second_class" bson:"second_class"` // 以下字段只有在请求帖子列表时得到 Slogan string `json:"slogan,omitempty"` MemberNum int `json:"member_num,string,omitempty" bson:"member_num"` ThreadNum int `json:"thread_num,string,omitempty" bson:"thread_num"` PostNum int `json:"post_num,string,omitempty" bson:"post_num"` }
type Post ¶
type Post struct { ID string `json:"id"` AuthorID string `json:"author_id" bson:"author_id"` Title string `json:"title"` Floor int `json:"floor,string"` Time TiebaTime `json:"time"` Content []Content `json:"content"` ThreadID string `json:"thread_id" bson:"thread_id"` // 所属帖子ID, 需自行添加 }
func (Post) GenerateText ¶
type PostListResponse ¶
type PostListResponse struct { Forum Forum `json:"forum"` RequestUser RequestUser `json:"user"` Thread Thread `json:"thread"` Page page `json:"page"` PostList []struct { Post SubPostList subPostList `json:"sub_post_list"` } `json:"post_list"` UserList []User `json:"user_list"` ResponseStatus }
帖子详情接口
func (*PostListResponse) UnmarshalJSON ¶
func (plr *PostListResponse) UnmarshalJSON(b []byte) error
给楼层加上帖子ID, 给楼中楼加上楼层ID
type RequestUser ¶
type RequestUser struct { User IsLogin TiebaBool `json:"is_login"` IsManager TiebaBool `json:"is_manager"` IsMem TiebaBool `json:"is_mem"` }
当前请求用户, 用于检查登录状态和所在贴吧权限
type ResponseStatus ¶
type ResponseStatus struct { ErrorCode int `json:"error_code,string"` ErrorMsg string `json:"error_msg"` }
func (ResponseStatus) CheckStatus ¶
func (status ResponseStatus) CheckStatus() error
func (ResponseStatus) String ¶
func (status ResponseStatus) String() string
type SubPost ¶
type SubPost struct { ID string `json:"id"` AuthorID string `json:"author_id" bson:"author_id"` Title string `json:"title"` Floor int `json:"floor,string"` Time TiebaTime `json:"time"` Content []Content `json:"content"` PostID string `json:"post_id" bson:"post_id"` // 楼中楼所属楼层ID, 需自行添加 }
将楼层和楼中楼分开存储 楼中楼的数据不是完整的, 后期可能会添加完整楼中楼的获取方式 虽然其内容类型与楼层是一样的, 但其重要性更低
type TextGenerator ¶
type TextGenerator interface {
GenerateText() string
}
type Thread ¶
type Thread struct { ID string `json:"id"` Title string `json:"title"` ReplyNum int `json:"reply_num,string" bson:"reply_num"` CreateTime TiebaTime `json:"create_time" bson:"create_time"` // 类型为时间戳, 可能不存在此字段, 比如为直播贴 IsActivity TiebaBool `json:"is_activity" bson:"is_activity"` // 活动帖 // 以下字段只有在请求帖子列表时得到 AuthorID string `json:"author_id" bson:"author_id"` LastTime TiebaTime `json:"last_time_int" bson:"last_time"` // 类型为时间戳 ViewNum TiebaUInt `json:"view_num" bson:"view_num"` // 浏览量, 可能为 NAN, INF IsTop TiebaBool `json:"is_top" bson:"is_top"` // 置顶帖 IsGood TiebaBool `json:"is_good" bson:"is_good"` // 精品贴 IsNotice TiebaBool `json:"is_notice" bson:"is_notice"` // 通知贴 IsBakan TiebaBool `json:"is_bakan" bson:"is_bakan"` // 吧刊贴 IsVote TiebaBool `json:"is_vote" bson:"is_vote"` // 投票贴 IsLivePost TiebaBool `json:"is_livepost" bson:"is_livepost"` // 直播贴, 不一定有此字段 ForumID string `json:"forum_id" bson:"forum_id"` // 所属贴吧ID, 需自行添加 }
帖子列表请求返回的响应有 id 和 tid 两个字段, 当帖子没有 tid 时是一个广告贴 reply_num 包括了楼中楼数量, 为总回帖量(不包括一楼), 不能用来计算页数 media 包含了帖子概览时的媒体文件, 这里不
type ThreadListResponse ¶
type ThreadListResponse struct { Forum Forum `json:"forum"` RequestUser RequestUser `json:"user"` Page page `json:"page"` ThreadList threadList `json:"thread_list"` UserList []User `json:"user_list"` ResponseStatus }
贴吧搜索接口数据结构
type TiebaBool ¶
type TiebaBool bool
func (*TiebaBool) UnmarshalJSON ¶
将贴吧接口返回的布尔值字符串转换为布尔值, 空字符串转换为false
type TiebaTime ¶
https://medium.com/coding-and-deploying-in-the-cloud/time-stamps-in-golang-abcaf581b72f 使用继承而不是类型别名来获得time.Time的方法, 注意我们解析得到的是UTC时间
func (*TiebaTime) UnmarshalJSON ¶
type TiebaUInt ¶
type TiebaUInt int
func (*TiebaUInt) UnmarshalJSON ¶
将贴吧接口返回的无符号整数字符串转换为整数, 这里的无符号整数字符串指的是数据为十进制, 实际意义非负, 可能为NAN, INF 当为NAN时将值置为-1, 为INF时置为-2