api

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2026 License: MIT Imports: 13 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const BaseURL = "https://bbs.nga.cn"

BaseURL 为 NGA 主站。

View Source
const DefaultUA = "NGA_WP_JW"

默认 User-Agent。NGA 对非移动端 UA 会返回反爬 error 15(访客不能直接访问), 使用移动端 UA 可绕过。

View Source
const PageSize = 50

PageSize 是帖子列表的每页条数(NGA 移动接口固定 50)。

View Source
const ReadPageSize = 20

ReadPageSize 是帖子阅读接口的每页楼层数(read.php 的 __R__ROWS_PAGE,通常 20)。

Variables

This section is empty.

Functions

func FixJSON

func FixJSON(data []byte) []byte

FixJSON 导出预处理函数,供调试/测试使用。

Types

type APIError

type APIError struct {
	Code string
}

APIError 表示 NGA 返回的业务错误,Code 形如 "15:访客不能直接访问"。

func (*APIError) Error

func (e *APIError) Error() string

type Client

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

Client 是 NGA 数据层核心:持有 UA、cookie 与请求限速。

func NewClient

func NewClient() *Client

NewClient 创建默认客户端。

func (*Client) CheckLogin

func (c *Client) CheckLogin() (bool, error)

CheckLogin 通过登录门槛接口判断当前 cookie 是否有效。 未登录时 NGA 明确返回 2048:尚未登录,返回 (false, nil); 请求本身失败(网络/HTTP)时返回错误。

func (*Client) Cookies

func (c *Client) Cookies() map[string]string

Cookies 返回当前 cookie 副本,供持久化。

func (*Client) Get

func (c *Client) Get(path string, params url.Values) ([]byte, error)

Get 发起 GET 请求,返回原始响应体。

func (*Client) GetCategories

func (c *Client) GetCategories() ([]model.Category, error)

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) LoggedIn

func (c *Client) LoggedIn() bool

LoggedIn 粗略判断是否带上了 passport cookie。

func (*Client) SetCookies

func (c *Client) SetCookies(cs map[string]string)

SetCookies 设置手动附加的 cookie(ngaPassportUid / ngaPassportCid 等)。

func (*Client) SetOnCookiesChanged

func (c *Client) SetOnCookiesChanged(fn func())

SetOnCookiesChanged 注册会话 cookie 变化回调(跟随 Set-Cookie 轮换后触发)。

type HTTPError

type HTTPError struct {
	Status int
	URL    string
}

HTTPError 表示非 200 的 HTTP 响应。

func (*HTTPError) Error

func (e *HTTPError) Error() string

type Session

type Session struct {
	UID string
	// Cookies 是需要附加到 bbs.nga.cn 请求的 passport cookie。
	Cookies map[string]string
}

Session 表示登录状态。

type ThreadContentResult

type ThreadContentResult struct {
	Replies []model.Reply // 楼层,按服务端顺序(主楼在前)
	Users   map[int]model.User
	Page    int
	Pages   int
	Rows    int // 总楼层数(含主楼)
}

ThreadContentResult 是 read.php 的解析结果。

type ThreadListResult

type ThreadListResult struct {
	Threads []model.Thread
	Page    int
	Pages   int
	OrderBy string
	// SubForums 当前版面的子版面/合集(来自 __F.sub_forums)。
	SubForums []model.SubForum
	// BoardName 当前版面的真实名称(来自 __F,直达时用于回填标题与收藏名)。
	BoardName string
}

ThreadListResult 是帖子列表接口的解析结果。

Jump to

Keyboard shortcuts

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