Documentation
¶
Overview ¶
Package yunxiao is a native Go client for Alibaba Cloud DevOps (Yunxiao) OpenAPI.
It does not wrap the Node MCP server; requests use the x-yunxiao-token header against openapi-rdc.aliyuncs.com (central) or a region edition base URL.
Layout ¶
this package (module root) — core Client, HTTP, path, catalog, platform codeup/ flow/ appstack/ … — domain services (public subpackages) cmd/yunxiao — optional CLI internal/cli, cliconfig — CLI only tools/codegen/mcp — MCP → requests + methods tools/codegen/response — response domain samples + generator
Quick start ¶
c, err := yunxiao.New(yunxiao.Config{
Token: os.Getenv("YUNXIAO_ACCESS_TOKEN"),
OrganizationID: os.Getenv("YUNXIAO_ORG_ID"),
MaxRetries: 2,
})
svc := codeup.New(c)
repos, err := svc.ListRepositoriesTyped(ctx, &codeup.ListRepositoriesRequest{Page: 1})
Domain packages contain:
- zz_types_gen.go / zz_gen.go — request models + Call/Into (from MCP)
- zz_response_gen.go — response models + Decoded (from samples)
- typed.go — hand-written convenience wrappers
Domains: codeup, flow, appstack, organization, packages, projex, testhub.
Index ¶
- Constants
- func CloneQuery(query map[string]any) map[string]any
- func DecodeJSON[T any](raw json.RawMessage, dest *T) error
- func DecodeList[T any](raw json.RawMessage) ([]T, error)
- func EncodeRepositoryID(repositoryID string) string
- func FillPath(template string, vars map[string]string) (string, error)
- func IsNotFound(err error) bool
- func IsRetriable(err error) bool
- func IsUnauthorized(err error) bool
- func Paginate[T any](ctx context.Context, opt PageOptions, fetch FetchPage[T]) ([]T, error)
- func PaginateQuery[T any](ctx context.Context, baseQuery map[string]any, opt PageOptions, ...) ([]T, error)
- func PathEscape(filePath string) string
- func WithPage(query map[string]any, page, perPage int) map[string]any
- func WithPageKeys(query map[string]any, pageKey, perPageKey string, page, perPage int) map[string]any
- type APIError
- type Client
- func (c *Client) BaseURL() string
- func (c *Client) Call(ctx context.Context, ...) (json.RawMessage, error)
- func (c *Client) CallOp(ctx context.Context, opName, organizationID string, pathVars map[string]string, ...) (json.RawMessage, error)
- func (c *Client) Clone() *Client
- func (c *Client) Do(ctx context.Context, method, p string, query map[string]any, body any) (json.RawMessage, error)
- func (c *Client) GetCurrentOrganizationInfo(ctx context.Context) (*CurrentOrganizationInfo, error)
- func (c *Client) GetCurrentUser(ctx context.Context) (*CurrentUser, error)
- func (c *Client) GetUserOrganizations(ctx context.Context) ([]Organization, error)
- func (c *Client) IsRegion() bool
- func (c *Client) LastOrganizationID() string
- func (c *Client) ResolveOrganizationID(ctx context.Context, explicit string) (string, error)
- func (c *Client) ResolvePath(ctx context.Context, organizationID, regionTemplate, centralTemplate string, ...) (string, error)
- func (c *Client) SetLastOrganizationID(id string)
- func (c *Client) WithOrganization(organizationID string) *Client
- type Config
- type CurrentOrganizationInfo
- type CurrentUser
- type FetchPage
- type FuncLogger
- type Logger
- type OpSpec
- type Organization
- type PageOptions
- type WriterLogger
Constants ¶
const DefaultBaseURL = "https://openapi-rdc.aliyuncs.com"
const DefaultClientRetries = 2
DefaultMaxRetries is used when Config.MaxRetries is negative (unset sentinel not used; zero means no retries; omit by leaving at 0 and set explicitly, or use DefaultClientRetries).
const Version = "0.1.0"
Version is the SDK release version. CLI defaults to the same value unless overridden at build time.
Variables ¶
This section is empty.
Functions ¶
func CloneQuery ¶
CloneQuery returns a shallow copy of query (nil-safe).
func DecodeJSON ¶
func DecodeJSON[T any](raw json.RawMessage, dest *T) error
DecodeJSON unmarshals raw into dest.
func DecodeList ¶
func DecodeList[T any](raw json.RawMessage) ([]T, error)
DecodeList unmarshals either a JSON array or an object with an items/list/data array field.
func EncodeRepositoryID ¶
EncodeRepositoryID encodes org/name style repository ids.
func IsRetriable ¶
IsRetriable reports whether the client should retry the request. Network errors are treated as retriable; API errors only when Temporary.
func IsUnauthorized ¶
IsUnauthorized reports whether err is an API 401/403.
func PaginateQuery ¶
func PaginateQuery[T any](ctx context.Context, baseQuery map[string]any, opt PageOptions, fetch func(ctx context.Context, query map[string]any) ([]T, error)) ([]T, error)
PaginateQuery is a convenience for APIs that take map[string]any query with page/perPage.
func PathEscape ¶
PathEscape keeps slashes unescaped for file paths (MCP pathEscape).
Types ¶
type APIError ¶
type APIError struct {
Status int
Method string
URL string
Body []byte
Code string
Message string
RequestID string
}
APIError is a non-2xx Yunxiao OpenAPI response.
func AsAPIError ¶
AsAPIError extracts *APIError from err if present.
func ParseAPIErrorBody ¶
ParseAPIErrorBody fills Code/Message/RequestID from JSON body when possible.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a native Yunxiao OpenAPI client (no MCP).
func NewWithDefaults ¶
NewWithDefaults creates a Client with DefaultClientRetries when MaxRetries is 0.
func (*Client) Call ¶
func (c *Client) Call(ctx context.Context, method, organizationID, regionTemplate, centralTemplate string, pathVars map[string]string, query map[string]any, body any) (json.RawMessage, error)
Call is a generic OpenAPI invocation used by generated methods and CLI.
func (*Client) CallOp ¶
func (c *Client) CallOp(ctx context.Context, opName, organizationID string, pathVars map[string]string, query map[string]any, body any) (json.RawMessage, error)
CallOp looks up catalog operation by name and executes it.
func (*Client) Do ¶
func (c *Client) Do(ctx context.Context, method, p string, query map[string]any, body any) (json.RawMessage, error)
Do performs a raw OpenAPI request. path may be absolute or start with /. Retriable failures honor MaxRetries / RetryWait (see Config).
func (*Client) GetCurrentOrganizationInfo ¶
func (c *Client) GetCurrentOrganizationInfo(ctx context.Context) (*CurrentOrganizationInfo, error)
GetCurrentOrganizationInfo maps /platform/user like the MCP server.
func (*Client) GetCurrentUser ¶
func (c *Client) GetCurrentUser(ctx context.Context) (*CurrentUser, error)
GetCurrentUser returns the token user.
func (*Client) GetUserOrganizations ¶
func (c *Client) GetUserOrganizations(ctx context.Context) ([]Organization, error)
GetUserOrganizations lists organizations for current user. Organization response fields are generated from help docs (see zz_response_gen.go).
func (*Client) LastOrganizationID ¶
LastOrganizationID returns cached organization id if known.
func (*Client) ResolveOrganizationID ¶
ResolveOrganizationID mirrors MCP resolveOrganizationId behavior.
func (*Client) ResolvePath ¶
func (c *Client) ResolvePath(ctx context.Context, organizationID, regionTemplate, centralTemplate string, vars map[string]string) (string, error)
ResolvePath picks region/central template and fills params. organizationId is resolved when the chosen template needs it.
func (*Client) SetLastOrganizationID ¶
SetLastOrganizationID overrides cached organization id.
func (*Client) WithOrganization ¶
WithOrganization returns a clone with default organization id set.
type Config ¶
type Config struct {
// Token is the personal access token (x-yunxiao-token).
Token string
// BaseURL defaults to https://openapi-rdc.aliyuncs.com
BaseURL string
// Edition is "central" or "region". Empty auto-detects from BaseURL.
Edition string
// RegionDefaultOrgID used when edition is region (default "default").
RegionDefaultOrgID string
// OrganizationID is the default organization for central edition path resolution.
OrganizationID string
// HTTPClient optional custom client. If nil, a client with 60s timeout is used.
HTTPClient *http.Client
// Debug enables request logging via Logger (defaults to stderr when true).
Debug bool
// Logger receives debug lines. Optional; when Debug is true and Logger is nil, stderr is used.
Logger Logger
// MaxRetries is the number of retries after the first attempt for retriable failures
// (network errors, 429, 502, 503, 504). 0 disables retries. Default when using
// NewWithDefaults is DefaultClientRetries; New leaves 0 unless set.
MaxRetries int
// RetryWait is the base backoff between retries (doubled each attempt). Default 200ms.
RetryWait time.Duration
// UserAgent overrides the default User-Agent header when non-empty.
UserAgent string
}
Config configures the Yunxiao OpenAPI client.
type CurrentOrganizationInfo ¶
type CurrentOrganizationInfo struct {
LastOrganization string `json:"lastOrganization"`
UserID string `json:"userId"`
UserName string `json:"userName"`
}
CurrentOrganizationInfo is a mapped view used by MCP get_current_organization_info.
type CurrentUser ¶
type CurrentUser struct {
ID string `json:"id"`
Name string `json:"name"`
Email string `json:"email"`
LastOrganization string `json:"lastOrganization"`
CreatedAt string `json:"createdAt"`
}
CurrentUser is GET /oapi/v1/platform/user
type FetchPage ¶
FetchPage loads a single page of results. page is 1-based. Return fewer than perPage items (or empty) to signal the last page.
type FuncLogger ¶
FuncLogger adapts a function to Logger.
func (FuncLogger) Printf ¶
func (f FuncLogger) Printf(format string, v ...any)
Printf implements Logger.
type Logger ¶
Logger is a minimal debug logger. Implementations must be safe for concurrent use if the Client is shared across goroutines.
type OpSpec ¶
type OpSpec struct {
Name string `json:"name"`
GoName string `json:"goName"`
Domain string `json:"domain"`
Method string `json:"method"`
RegionPath string `json:"regionPath"`
CentralPath string `json:"centralPath"`
PathParams []string `json:"pathParams"`
QueryKeys []string `json:"queryKeys"`
BodyKeys []string `json:"bodyKeys"`
Required []string `json:"required"`
HasBody bool `json:"hasBody"`
Source string `json:"source"`
File string `json:"file"`
}
OpSpec describes one OpenAPI operation derived from MCP server source.
func LookupOperation ¶
LookupOperation finds an operation by cli name, Go name, or source name.
func Operations ¶
Operations returns all parsed OpenAPI operations.
type Organization ¶
type Organization struct {
CreatedAt string `json:"createdAt,omitempty"`
CreatorID string `json:"creatorId,omitempty"`
DefaultRole string `json:"defaultRole,omitempty"`
Description string `json:"description,omitempty"`
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
UpdateAt string `json:"updateAt,omitempty"`
}
Organization response domain model.
source: samples/organization_list.json
func DecodeOrganizationList ¶
func DecodeOrganizationList(raw json.RawMessage) ([]Organization, error)
DecodeOrganizationList decodes organization list payloads.
type PageOptions ¶
type PageOptions struct {
// StartPage defaults to 1.
StartPage int
// PerPage defaults to 20.
PerPage int
// MaxPages caps how many pages to fetch; 0 means unlimited (until a short page).
MaxPages int
// PageKey defaults to "page".
PageKey string
// PerPageKey defaults to "perPage".
PerPageKey string
}
PageOptions controls automatic pagination helpers.
type WriterLogger ¶
WriterLogger logs to an io.Writer (e.g. os.Stderr).
func (WriterLogger) Printf ¶
func (l WriterLogger) Printf(format string, v ...any)
Printf implements Logger.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
yunxiao
command
|
|
|
examples
|
|
|
list_repos
command
Example: list Codeup repositories via the domain service.
|
Example: list Codeup repositories via the domain service. |
|
whoami
command
Example: print current Yunxiao user.
|
Example: print current Yunxiao user. |
|
internal
|
|