Documentation
¶
Index ¶
- Constants
- func FixJSON(data []byte) []byte
- type APIError
- type Client
- func (c *Client) CheckLogin() (bool, error)
- func (c *Client) Cookies() map[string]string
- func (c *Client) Get(path string, params url.Values) ([]byte, error)
- func (c *Client) GetCategories() ([]model.Category, error)
- func (c *Client) GetThreadContent(tid int, page int) (*ThreadContentResult, error)
- func (c *Client) GetThreads(fid, stid string, page int, orderBy, keyword string) (*ThreadListResult, error)
- func (c *Client) LoggedIn() bool
- func (c *Client) SetCookies(cs map[string]string)
- func (c *Client) SetOnCookiesChanged(fn func())
- type HTTPError
- type Session
- type ThreadContentResult
- type ThreadListResult
Constants ¶
const BaseURL = "https://bbs.nga.cn"
BaseURL 为 NGA 主站。
const DefaultUA = "NGA_WP_JW"
默认 User-Agent。NGA 对非移动端 UA 会返回反爬 error 15(访客不能直接访问), 使用移动端 UA 可绕过。
const PageSize = 50
PageSize 是帖子列表的每页条数(NGA 移动接口固定 50)。
const ReadPageSize = 20
ReadPageSize 是帖子阅读接口的每页楼层数(read.php 的 __R__ROWS_PAGE,通常 20)。
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client 是 NGA 数据层核心:持有 UA、cookie 与请求限速。
func (*Client) CheckLogin ¶
CheckLogin 通过登录门槛接口判断当前 cookie 是否有效。 未登录时 NGA 明确返回 2048:尚未登录,返回 (false, nil); 请求本身失败(网络/HTTP)时返回错误。
func (*Client) GetCategories ¶
GetCategories 拉取版面分类(三级:分类→分组→版面)。
func (*Client) GetThreadContent ¶
func (c *Client) GetThreadContent(tid int, page int) (*ThreadContentResult, error)
GetThreadContent 拉取帖子某一页的内容。
func (*Client) GetThreads ¶
func (c *Client) GetThreads(fid, stid string, page int, orderBy, keyword string) (*ThreadListResult, error)
GetThreads 拉取版面的帖子列表;keyword 非空时执行版内搜索。 stid 非空时按合集打开(thread.php?stid=...),否则按 fid 打开。
func (*Client) SetCookies ¶
SetCookies 设置手动附加的 cookie(ngaPassportUid / ngaPassportCid 等)。
func (*Client) SetOnCookiesChanged ¶
func (c *Client) SetOnCookiesChanged(fn func())
SetOnCookiesChanged 注册会话 cookie 变化回调(跟随 Set-Cookie 轮换后触发)。
type Session ¶
type Session struct {
UID string
// Cookies 是需要附加到 bbs.nga.cn 请求的 passport cookie。
Cookies map[string]string
}
Session 表示登录状态。