Go wrapper around Xray-core for mobile and desktop clients. Keep platform-specific App behavior out of the generic library.
When changing a public API contract, read README API, the
affected method section, and invoke_model.go / invoke.go. Internal-only
changes need the relevant implementation and tests, not the entire API guide.
- Keep
LibXrayAPIVersionfixed at3; do not increment it within this release. Synchronize contract changes with typed models, downstream consumers, tests, and bothREADME.mdandreadme/README.zh_CN.md. - Applications use
Invoke/CGoInvokewith typed requests. Config methods receivexrayJsontext, not configuration file paths. Runtimeenvbelongs inside that Xray JSON. File-oriented APIs and the desktop Core CLI retain file access. TestXrayconstructs an instance throughnewXrayInstanceand closes it without callingStart. Callers own minimal/filtered validation configs. Process-level side effects are accepted; startup resources and connectivity remain outside this check. See testXray for limitations.- Manage one running instance. Validation and temporary instances must reject managed-instance overlap before loading configuration and hold the lifecycle lock through worker completion and instance cleanup. Close temporary instances on every exit path; unmanaged overlaps require caller-owned process isolation.
- When changing batch probes, preserve input order,
per-item failure isolation, and raw
locationJson; provider parsing belongs to the App. - Traffic comes directly from Xray metrics. The library manages the Core lifecycle only; it does not sample or persist traffic.
- When changing age subscriptions, keep key generation/decryption in libXray and HTTP/persistence in the App. Never log secret keys, decrypted subscriptions, or requests containing them.
Before changing platform bridges or build scripts, read build and the relevant platform/controller section in README.
- Free each non-null
CGoInvokeresponse exactly once withCGoFree. Load only one independently built Go runtime per process. - Keep Android-only APIs behind the
androidbuild tag. When changing DNS integration, read DNS resolver:SetDNSaffects the process resolver andResetDNSfollows managed-instance shutdown. - Use
build/main.pyto generate native artifacts; do not edit generated headers, archives, or binaries. Verify temporary module edits are restored after a build and check the build command's success and resulting artifacts. - Modify an adjacent Xray-core checkout only when explicitly requested.
Targets and local-core options are documented in build usage.
GitHub Issues for XTLS/libXray. Before issue, PR or review work, read
issue tracker.
Use the five canonical triage labels. Before triage, read label mapping.
Single-context layout. Before codebase exploration or domain/ADR work, read domain guidance.
Run git diff --check for all changes. Match further verification to the change;
expand or repeat checks only for new changes, failures, or unresolved concerns.
- Go changes:
gofmtchanged files and run affected tests. Usego test ./... -count=1for shared lifecycle, API, or dependency changes, or when the impact cannot be contained to specific packages. - Invoke changes: cover dispatch/models, response shapes, and removed methods where relevant; verify downstream request models against the same contract.
- Bridge/build changes: build the affected artifact where supported. Report unsupported targets or unbuilt artifacts explicitly.
- Documentation-only changes: check referenced paths/anchors; no Go tests or native builds are needed.