yuque package - github.com/flc1125/go-yuque - Go Packages

yuque

package module
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2026 License: MIT Imports: 13 Imported by: 0

README

🚀 Go-Yuque-SDK

Supported Go Versions Package Version GoDoc codecov lint tests MIT license

The Go-Yuque-SDK is a Go client library for accessing the Yuque API.

[!WARNING]

This is currently still a non-stable version, is not recommended for production use.

If you encounter any issues, you are welcome to submit an issue.

📥 Installation

go get github.com/flc1125/go-yuque

✨ Features

see features.md

📜 License

The MIT License (MIT). Please see License File for more information.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsErrorResponse

func IsErrorResponse(err error) bool

func NewRetryableHTTPClient

func NewRetryableHTTPClient(opts ...RetryableHTTPClientOption) *http.Client

func Ptr deprecated

func Ptr[T any](v T) *T

Ptr is a helper function to get the pointer of a value.

Deprecated: Use new(v) instead. Go 1.26 allows new to take an expression.

Types

type AccessType

type AccessType int

AccessType 文档/知识库公开性:公开性 (0:私密, 1:公开, 2:企业内公开)

const (
	AccessTypePrivate AccessType = 0 // 私密
	AccessTypePublic  AccessType = 1 // 公开
	AccessTypeInner   AccessType = 2 // 企业内公开
)

type Book

type Book struct {
	ID               int        `json:"id"`
	Type             BookType   `json:"type"`
	Slug             string     `json:"slug"`
	Name             string     `json:"name"`
	UserID           int        `json:"user_id"`
	Description      string     `json:"description"`
	TocYML           string     `json:"toc_yml"`
	CreatorID        int        `json:"creator_id"`
	Public           AccessType `json:"public"`
	ItemsCount       int        `json:"items_count"`
	LikesCount       int        `json:"likes_count"`
	WatchesCount     int        `json:"watches_count"`
	ContentUpdatedAt time.Time  `json:"content_updated_at"`
	CreatedAt        time.Time  `json:"created_at"`
	UpdatedAt        time.Time  `json:"updated_at"`
	Namespace        string     `json:"namespace"`
	User             *User      `json:"user"`
}

type BookType

type BookType string

BookType 类型 (Book:文档, Design:图集, Sheet:表格, Resource:资源)

const (
	BookTypeBook     BookType = "Book"     // 文档
	BookTypeDesign   BookType = "Design"   // 图集
	BookTypeSheet    BookType = "Sheet"    // 表格
	BookTypeResource BookType = "Resource" // 资源
)

type Client

type Client struct {

	// services used for talking to different parts of the Tapd API.
	UserService      *userService
	DocService       *docService
	StatisticService *statisticService
	// contains filtered or unexported fields
}

func NewClient

func NewClient(token string, opts ...ClientOption) (*Client, error)

NewClient returns a new Tapd API client. Alias for NewBasicAuthClient.

func (*Client) Do

func (c *Client) Do(req *http.Request, v any) (*Response, error)

func (*Client) NewRequest

func (c *Client) NewRequest(ctx context.Context, method, path string, data any, opts []RequestOption) (*http.Request, error)

type ClientOption

type ClientOption func(*Client) error

func WithBaseURL

func WithBaseURL(urlStr string) ClientOption

WithBaseURL sets the baseURL for the client

func WithHTTPClient

func WithHTTPClient(httpClient *http.Client) ClientOption

func WithToken

func WithToken(token string) ClientOption

WithToken sets the token for the client

func WithUserAgent

func WithUserAgent(userAgent string) ClientOption

type CreateDocRequest

type CreateDocRequest struct {
	Slug   *string     `json:"slug,omitempty"`   // 路径
	Title  *string     `json:"title,omitempty"`  // 标题,默认:无标题
	Public *AccessType `json:"public,omitempty"` // 公开性 (0:私密, 1:公开, 2:企业内公开) 不填则继承知识库的公开性
	Format *DocFormat  `json:"format,omitempty"` // 内容格式 (markdown:Markdown 格式, html:HTML 标准格式, lake:语雀 Lake 格式) 不填则默认为 markdown
	Body   *string     `json:"body,omitempty"`   // 正文内容
}

type Doc

type Doc struct {
	ID               int        `json:"id,omitempty"`
	Type             DocType    `json:"type,omitempty"`
	Slug             string     `json:"slug,omitempty"`
	Title            string     `json:"title,omitempty"`
	Description      string     `json:"description,omitempty"`
	Cover            string     `json:"cover,omitempty"`
	UserID           int        `json:"user_id,omitempty"`
	BookID           int        `json:"book_id,omitempty"`
	LastEditorID     int        `json:"last_editor_id,omitempty"`
	Public           AccessType `json:"public,omitempty"`
	Status           int        `json:"status,omitempty"`
	LikesCount       *int       `json:"likes_count,omitempty"`
	ReadCount        int        `json:"read_count,omitempty"`
	CommentsCount    *int       `json:"comments_count,omitempty"`
	WordCount        int        `json:"word_count,omitempty"`
	CreatedAt        time.Time  `json:"created_at,omitzero"`
	UpdatedAt        time.Time  `json:"updated_at,omitzero"`
	ContentUpdatedAt time.Time  `json:"content_updated_at,omitzero"`
	PublishedAt      time.Time  `json:"published_at,omitzero"`
	FirstPublishedAt time.Time  `json:"first_published_at,omitzero"`
	User             *User      `json:"user,omitempty"`
	LastEditor       *User      `json:"last_editor,omitempty"`
	Hits             int        `json:"hits,omitempty"`

	// 以下字段是创建文档、获取文档详情等时才有的字段
	Format          *DocFormat `json:"format,omitempty"`
	BodyDraft       *string    `json:"body_draft,omitempty"`
	Body            *string    `json:"body,omitempty"`
	BodySheet       *string    `json:"body_sheet,omitempty"`
	BodyTable       *string    `json:"body_table,omitempty"`
	BodyHTML        *string    `json:"body_html,omitempty"`
	BodyLake        *string    `json:"body_lake,omitempty"`
	Book            *Book      `json:"book,omitempty"`
	Creator         *User      `json:"creator,omitempty"`
	Tags            []*DocTag  `json:"tags,omitempty"`
	LatestVersionID int        `json:"latest_version_id,omitempty"`
}

type DocFormat

type DocFormat string

DocFormat 内容格式 (markdown:Markdown 格式, html:HTML 标准格式, lake:语雀 Lake 格式,lakesheet:语雀表格)

const (
	DocFormatMarkdown  DocFormat = "markdown"  // Markdown 格式
	DocFormatHTML      DocFormat = "html"      // HTML 标准格式
	DocFormatLake      DocFormat = "lake"      // 语雀 Lake 格式
	DocFormatLakeSheet DocFormat = "lakesheet" // 语雀表格
)

type DocTag added in v0.4.0

type DocTag struct {
	ID        int       `json:"id,omitempty"`
	Title     string    `json:"title,omitempty"`
	DocID     int       `json:"doc_id,omitempty"`
	BookID    int       `json:"book_id,omitempty"`
	UserID    int       `json:"user_id,omitempty"`
	CreatedAt time.Time `json:"created_at,omitzero"`
	UpdatedAt time.Time `json:"updated_at,omitzero"`
}

type DocType

type DocType string

DocType 文档类型 (Doc:普通文档, Sheet:表格, Thread:话题, Board:图集, Table:数据表)

const (
	DocTypeDoc    DocType = "Doc"    // 普通文档
	DocTypeSheet  DocType = "Sheet"  // 表格
	DocTypeThread DocType = "Thread" // 话题
	DocTypeBoard  DocType = "Board"  // 图集
	DocTypeTable  DocType = "Table"  // 数据表
)

type ErrorResponse

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

ErrorResponse represents a yuque error response.

func (*ErrorResponse) Error

func (e *ErrorResponse) Error() string

func (*ErrorResponse) Unwrap

func (e *ErrorResponse) Unwrap() error

type GetDocsRequest

type GetDocsRequest struct {
	// 偏移量 [分页参数]
	Offset *int `url:"offset,omitempty"`

	// 每页数量 [分页参数]
	Limit *int `url:"limit,omitempty"`

	// 获取的额外字段, 多个字段以逗号分隔
	//
	// 注意: 每页数量超过 100 本字段会失效
	//
	// 支持的字段有:
	//
	// hits: 文档阅读数
	// tags: 标签
	// latest_version_id: 最新已发版本 ID
	OptionalProperties *string `url:"optional_properties,omitempty"`
}

type GetDocsResponse

type GetDocsResponse struct {
	Total int    `json:"total,omitempty"`
	Docs  []*Doc `json:"docs,omitempty"`
}

type GetGroupStatisticsResponse added in v0.2.0

type GetGroupStatisticsResponse struct {
	BizDate                string  `json:"bizdate,omitempty"`
	UserID                 int     `json:"user_id,omitempty"`
	OrganizationID         int     `json:"organization_id,omitempty"`
	MemberCount            int     `json:"member_count,omitempty"`             // 成员数
	CollaboratorCount      int     `json:"collaborator_count,omitempty"`       // 协作者数
	DayReadCount           int     `json:"day_read_count,omitempty"`           // 当日阅读量
	DayWriteCount          int     `json:"day_write_count,omitempty"`          // 当日编辑次数
	WriteCount             int     `json:"write_count,omitempty"`              // 编辑次数
	ReadCount              int     `json:"read_count,omitempty"`               // 阅读量
	ReadCount30            int     `json:"read_count_30,omitempty"`            // 阅读量 (30天)
	ReadCount365           int     `json:"read_count_365,omitempty"`           // 阅读量 (一年)
	CommentCount           int     `json:"comment_count,omitempty"`            // 评论量
	CommentCount30         int     `json:"comment_count_30,omitempty"`         // 评论量 (30天)
	CommentCount365        int     `json:"comment_count_365,omitempty"`        // 评论量 (一年)
	LikeCount              int     `json:"like_count,omitempty"`               // 点赞量
	LikeCount30            int     `json:"like_count_30,omitempty"`            // 点赞量 (30天)
	LikeCount365           int     `json:"like_count_365,omitempty"`           // 点赞量 (一年)
	FollowCount            int     `json:"follow_count,omitempty"`             // 关注量
	CollectCount           int     `json:"collect_count,omitempty"`            // 收藏量
	DocCount               int     `json:"doc_count,omitempty"`                // 文档数量
	SheetCount             int     `json:"sheet_count,omitempty"`              // 表格数量
	BoardCount             int     `json:"board_count,omitempty"`              // 画板数量
	ShowCount              int     `json:"show_count,omitempty"`               // 演示文稿数量
	ResourceCount          int     `json:"resource_count,omitempty"`           // 资源数量
	ArtBoardCount          int     `json:"artboard_count,omitempty"`           // 图集数量
	AttachmentCount        int     `json:"attachment_count,omitempty"`         // 附件数量
	BookCount              int     `json:"book_count,omitempty"`               // 知识库总数量
	PublicBookCount        int     `json:"public_book_count,omitempty"`        // 公开知识库数量
	PrivateBookCount       int     `json:"private_book_count,omitempty"`       // 私密知识库数量
	BookBookCount          int     `json:"book_book_count,omitempty"`          // 文档知识库数量
	BookResourceCount      int     `json:"book_resource_count,omitempty"`      // 资源知识库数量
	BookDesignCount        int     `json:"book_design_count,omitempty"`        // 图片知识库数量
	BookThreadCount        int     `json:"book_thread_count,omitempty"`        // 话题知识库数量
	DataUsage              int     `json:"data_usage,omitempty"`               // 流量使用量
	GrainsCount            int     `json:"grains_count,omitempty"`             // 当前稻谷数
	GrainsCountSum         int     `json:"grains_count_sum,omitempty"`         // 累计获得稻谷数
	GrainsCountConsume     int     `json:"grains_count_consume,omitempty"`     // 已消耗稻谷数
	InteractionPeopleCount int     `json:"interaction_people_count,omitempty"` // 知识交流人数
	ContentCount           int     `json:"content_count,omitempty"`            // 知识财富数
	CollaborationCount     int     `json:"collaboration_count,omitempty"`      // 知识协同次数
	WorkingHours           int     `json:"working_hours,omitempty"`            // 协同提效时长 (小时)
	Baike                  float64 `json:"baike,omitempty"`                    // 百科全书卷数
	TableCount             int     `json:"table_count,omitempty"`
}

type HelloResponse

type HelloResponse struct {
	Message string `json:"message,omitempty"`
}

type Meta

type Meta struct {
	Total int `json:"total,omitempty"`
}

type RawBody

type RawBody struct {
	Status  int             `json:"status,omitempty"`
	Meta    *Meta           `json:"meta,omitempty"`
	Data    json.RawMessage `json:"data,omitempty"`
	Message string          `json:"info,omitempty"`
}

RawBody represents a raw body.

type RequestOption

type RequestOption func(*http.Request) error

func WithRequestBasicAuth

func WithRequestBasicAuth(username, password string) RequestOption

func WithRequestHeader

func WithRequestHeader(name, value string) RequestOption

func WithRequestHeaderFunc

func WithRequestHeaderFunc(fn func(http.Header)) RequestOption

func WithRequestHeaders

func WithRequestHeaders(headers map[string]string) RequestOption

func WithRequestUserAgent

func WithRequestUserAgent(userAgent string) RequestOption

type Response

type Response struct {
	*http.Response
	// contains filtered or unexported fields
}

Response represents an API response.

type RetryableHTTPClientOption

type RetryableHTTPClientOption func(client *retryablehttp.Client)

func WithRetryableHTTPClientBackoff

func WithRetryableHTTPClientBackoff(backoff retryablehttp.Backoff) RetryableHTTPClientOption

func WithRetryableHTTPClientCheckRetry

func WithRetryableHTTPClientCheckRetry(checkRetry retryablehttp.CheckRetry) RetryableHTTPClientOption

func WithRetryableHTTPClientLogger

func WithRetryableHTTPClientLogger(logger retryablehttp.Logger) RetryableHTTPClientOption

func WithRetryableHTTPClientRetryMax

func WithRetryableHTTPClientRetryMax(retryMax int) RetryableHTTPClientOption

func WithRetryableHTTPClientRetryWaitMax

func WithRetryableHTTPClientRetryWaitMax(waitMax time.Duration) RetryableHTTPClientOption

func WithRetryableHTTPClientRetryWaitMin

func WithRetryableHTTPClientRetryWaitMin(waitMin time.Duration) RetryableHTTPClientOption

type TOC added in v0.2.0

type TOC struct {
	UUID        string  `json:"uuid,omitempty"`         // 节点唯一 ID
	Type        TOCType `json:"type,omitempty"`         // Enum: "DOC" "LINK" "TITLE" 节点类型 (DOC:文档, LINK:外链, TITLE:分组)
	Title       string  `json:"title,omitempty"`        // 节点名称
	URL         string  `json:"url,omitempty"`          // 节点 URL
	Slug        string  `json:"slug,omitempty"`         // Deprecated 节点 URL
	ID          int     `json:"id,omitempty"`           // Deprecated 文档 ID
	DocID       int     `json:"doc_id,omitempty"`       // 文档 ID
	Level       int     `json:"level,omitempty"`        // 节点层级
	Depth       int     `json:"depth,omitempty"`        // Deprecated 节点层级
	OpenWindow  int     `json:"open_window,omitempty"`  // 是否在新窗口打开 (0:当前页打开, 1:新窗口打开)
	Visible     int     `json:"visible,omitempty"`      // 是否可见 (0:不可见, 1:可见)
	PrevUUID    string  `json:"prev_uuid,omitempty"`    // 同级前一个节点 uuid
	SiblingUUID string  `json:"sibling_uuid,omitempty"` // 同级后一个节点 uuid
	ChildUUID   string  `json:"child_uuid,omitempty"`   // 子级第一个节点 uuid
	ParentUUID  string  `json:"parent_uuid,omitempty"`  // 父级节点 uuid
}

type TOCType added in v0.2.0

type TOCType string
const (
	TOCTypeDoc   TOCType = "DOC"
	TOCTypeLink  TOCType = "LINK"
	TOCTypeTitle TOCType = "TITLE"
)

type User

type User struct {
	ID               int       `json:"id,omitempty"`
	Type             string    `json:"type,omitempty"`
	Login            string    `json:"login,omitempty"`
	Name             string    `json:"name,omitempty"`
	AvatarURL        string    `json:"avatar_url,omitempty"`
	BooksCount       int       `json:"books_count,omitempty"`
	PublicBooksCount int       `json:"public_books_count,omitempty"`
	FollowersCount   int       `json:"followers_count,omitempty"`
	FollowingCount   int       `json:"following_count,omitempty"`
	Public           int       `json:"public,omitempty"`
	Description      string    `json:"description,omitempty"`
	CreatedAt        time.Time `json:"created_at,omitzero"`
	UpdatedAt        time.Time `json:"updated_at,omitzero"`
	WorkID           string    `json:"work_id,omitempty"`
}

Jump to

Keyboard shortcuts

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