Documentation
¶
Index ¶
- func CheckLarkResponse(result interface{}) error
- func HandleResponse(resp *larkcore.ApiResp, opts ResponseOptions) error
- func IsJSONContentType(ct string) bool
- func PaginateWithJq(ctx context.Context, ac *APIClient, request RawApiRequest, jqExpr string, ...) error
- func ParseJSONResponse(resp *larkcore.ApiResp) (interface{}, error)
- func ResolveFilename(resp *larkcore.ApiResp) string
- func SaveResponse(resp *larkcore.ApiResp, outputPath string) (map[string]interface{}, error)
- type APIClient
- func (c *APIClient) CallAPI(ctx context.Context, request RawApiRequest) (interface{}, error)
- func (c *APIClient) DoAPI(ctx context.Context, request RawApiRequest) (*larkcore.ApiResp, error)
- func (c *APIClient) DoSDKRequest(ctx context.Context, req *larkcore.ApiReq, as core.Identity, ...) (*larkcore.ApiResp, error)
- func (c *APIClient) DoStream(ctx context.Context, req *larkcore.ApiReq, as core.Identity, opts ...Option) (*http.Response, error)
- func (c *APIClient) PaginateAll(ctx context.Context, request RawApiRequest, opts PaginationOptions) (interface{}, error)
- func (c *APIClient) StreamPages(ctx context.Context, request RawApiRequest, onItems func([]interface{}), ...) (result interface{}, hasItems bool, err error)
- type Option
- type PaginationOptions
- type RawApiRequest
- type ResponseOptions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CheckLarkResponse ¶
func CheckLarkResponse(result interface{}) error
CheckLarkResponse inspects a Lark API response for business-level errors (non-zero code). Uses type assertion instead of interface{} == nil to satisfy interface_nil_check lint. Returns nil if result is not a map, map is nil, or code is 0.
func HandleResponse ¶
func HandleResponse(resp *larkcore.ApiResp, opts ResponseOptions) error
HandleResponse routes a raw *larkcore.ApiResp to the appropriate output:
- If Content-Type is JSON, check for business errors first (even with --output).
- If --output is set and response is not a JSON error, save to file.
- If Content-Type is non-JSON and no --output, auto-save binary to file.
func IsJSONContentType ¶
IsJSONContentType reports whether the Content-Type header indicates a JSON response.
func PaginateWithJq ¶ added in v1.0.3
func PaginateWithJq(ctx context.Context, ac *APIClient, request RawApiRequest, jqExpr string, out io.Writer, pagOpts PaginationOptions, checkErr func(interface{}) error) error
PaginateWithJq aggregates all pages, checks for API errors, then applies a jq filter. If checkErr detects an error, the raw result is printed as JSON before returning the error.
func ParseJSONResponse ¶
ParseJSONResponse decodes a raw SDK response body as JSON. CallAPI and HandleResponse both delegate to this function.
func ResolveFilename ¶
ResolveFilename picks a filename from the response headers. Priority: Content-Disposition filename > Content-Type extension > "download.bin".
Types ¶
type APIClient ¶
type APIClient struct {
Config *core.CliConfig
SDK *lark.Client // All Lark API calls go through SDK
HTTP *http.Client // Only for non-Lark API (OAuth, MCP, etc.)
ErrOut io.Writer // debug/progress output
Credential *credential.CredentialProvider
}
APIClient wraps lark.Client for all Lark Open API calls.
func (*APIClient) CallAPI ¶
func (c *APIClient) CallAPI(ctx context.Context, request RawApiRequest) (interface{}, error)
CallAPI is a convenience wrapper: DoAPI + ParseJSONResponse. Use DoAPI directly when the response may not be JSON (e.g. file downloads).
func (*APIClient) DoAPI ¶
DoAPI executes a raw Lark SDK request and returns the raw *larkcore.ApiResp. Unlike CallAPI which always JSON-decodes, DoAPI returns the raw response — suitable for file downloads (pass larkcore.WithFileDownload() via request.ExtraOpts) and any endpoint whose Content-Type may not be JSON.
func (*APIClient) DoSDKRequest ¶
func (c *APIClient) DoSDKRequest(ctx context.Context, req *larkcore.ApiReq, as core.Identity, extraOpts ...larkcore.RequestOptionFunc) (*larkcore.ApiResp, error)
DoSDKRequest resolves auth for the given identity and executes a pre-built SDK request. This is the shared auth+execute path used by both DoAPI (generic API calls via RawApiRequest) and shortcut RuntimeContext.DoAPI (direct larkcore.ApiReq calls).
func (*APIClient) DoStream ¶ added in v1.0.5
func (c *APIClient) DoStream(ctx context.Context, req *larkcore.ApiReq, as core.Identity, opts ...Option) (*http.Response, error)
DoStream executes a streaming HTTP request against the Lark OpenAPI endpoint. Unlike DoSDKRequest (which buffers the full body via the SDK), DoStream returns a live *http.Response whose Body is an io.Reader for streaming consumption. Auth is resolved via Credential (same as DoSDKRequest). Security headers and any extra headers from opts are applied automatically. HTTP errors (status >= 400) are handled internally: the body is read (up to 4 KB), closed, and returned as an output.ErrNetwork — callers only receive successful responses.
func (*APIClient) PaginateAll ¶
func (c *APIClient) PaginateAll(ctx context.Context, request RawApiRequest, opts PaginationOptions) (interface{}, error)
PaginateAll fetches all pages and returns a single merged result. Use this for formats that need the complete dataset (e.g. JSON).
func (*APIClient) StreamPages ¶
func (c *APIClient) StreamPages(ctx context.Context, request RawApiRequest, onItems func([]interface{}), opts PaginationOptions) (result interface{}, hasItems bool, err error)
StreamPages fetches all pages and streams each page's list items via onItems. Returns the last page result (for error checking), whether any list items were found, and any network error. Use this for streaming formats (ndjson, table, csv).
type Option ¶ added in v1.0.5
type Option func(*requestConfig)
Option configures API request behavior for DoStream (and future DoSDKRequest).
func WithHeaders ¶ added in v1.0.5
WithHeaders adds extra HTTP headers to the request.
func WithTimeout ¶ added in v1.0.5
WithTimeout sets a request-level timeout that overrides the client default.
type PaginationOptions ¶
type PaginationOptions struct {
PageLimit int // max pages to fetch; 0 = unlimited (default: 10)
PageDelay int // ms, default 200
}
PaginationOptions contains pagination control options.
type RawApiRequest ¶
type RawApiRequest struct {
Method string
URL string
Params map[string]interface{}
Data interface{}
As core.Identity
ExtraOpts []larkcore.RequestOptionFunc // additional SDK request options (e.g. security headers)
}
RawApiRequest describes a raw API request.
type ResponseOptions ¶
type ResponseOptions struct {
OutputPath string // --output flag; "" = auto-detect
Format output.Format // output format for JSON responses
JqExpr string // if set, apply jq filter instead of Format
Out io.Writer // stdout
ErrOut io.Writer // stderr
// CheckError is called on parsed JSON results. Nil defaults to CheckLarkResponse.
CheckError func(interface{}) error
}
ResponseOptions configures how HandleResponse routes a raw API response.