Releases: apstndb/developerknowledge-go
Release list
v0.3.2
Highlights
Typed document retrieval
Client.GetDocument now retrieves a single document through the shared authenticated and retrying transport. It accepts the same WithDocumentView option as partial batch retrieval, including DOCUMENT_VIEW_BASIC for metadata-only responses that report contentLengthBytes without downloading document content.
DocumentOption is the shared option type for GetDocument and BatchGetDocumentsPartial. The existing BatchGetOption name remains as a type alias, so existing callers continue to compile unchanged.
The new method rejects invalid document names, unknown views, and malformed top-level null responses before returning a document.
Compatibility
This release is additive and does not contain breaking API changes. The existing BatchGetDocuments, BatchGetDocumentsAll, and BatchGetDocumentsPartial behavior remains unchanged.
v0.3.1
Highlights
Typed GA AnswerQuery support
Client.AnswerQuery now provides typed access to the GA v1 grounded-answer endpoint. The response models include UTF-8 byte-indexed citations and document references that reuse the package's existing Document and DocumentChunk types.
The method rejects nil or blank requests and malformed top-level null responses while preserving API errors for errors.As inspection through the existing request transport.
Partial batch retrieval and document views
BatchGetDocumentsPartial fetches input names in API-sized chunks, preserves input order and duplicate occurrences, and reports document-specific failures positionally without discarding successful results. Fatal request errors retain already completed results and leave later entries explicitly unprocessed.
WithDocumentView selects the API's BASIC, FULL, or CONTENT document views. Existing BatchGetDocuments and BatchGetDocumentsAll signatures and behavior are unchanged.
Compatibility
This release is additive and does not contain breaking API changes.
v0.3.0
Summary
v0.3.0 makes authenticated clients fail closed around credential discovery and request origins, corrects API error classification, and gives NormalizeDocName a strict invalid-input contract.
This release contains PR #21.
Breaking changes
Authenticated requests are origin-bound
Client.DoAPIRequest,DoGet, andDoJSONPostnow require the request URL to share the validated origin ofClient.BaseURL.- Clients returned by
NewAuthenticatedHTTPClientandNewADCHTTPClientrestrict initial requests and redirects toAuthConfig.AllowedOrigin, which defaults toDefaultV1BaseURL. - Redirects during
Clientrequests are same-origin-restricted even with a caller-suppliedHTTPClient; a customCheckRedirectcallback is chained, not replaced. - Origins must be canonical, hierarchical ASCII HTTP(S) URLs without userinfo. Request
Hostoverrides are also validated.
Migration: set AuthConfig.AllowedOrigin when a constructor-created authenticated client targets a non-default endpoint. A client used for https://apikeys.googleapis.com, for example, must explicitly allow that origin.
Explicit credential paths are strict
AuthConfig.CredentialsPath is evaluated exactly once and is now an explicit credential source. Missing, unreadable, malformed, or otherwise invalid files return an error instead of falling back to another ADC source.
Migration: omit CredentialsPath when standard platform or metadata-server ADC fallback is desired. Do not pass DefaultCredentialsPath merely to restate the default lookup behavior.
NormalizeDocName rejects invalid URL-like input
Empty or invalid input now returns "". URL-like input must be a hierarchical ASCII HTTP(S) URL without userinfo. Unsupported schemes, opaque URLs, protocol-relative URLs, malformed authorities, bracketed DNS/IPv4 authorities, and Unicode hostnames are rejected. Valid scheme-less host:port paths, including query- or fragment-only forms, and bracketed IPv6 paths remain supported.
For accepted URLs, hostnames are lowercased, default ports are stripped, percent-encoded path segments are preserved rather than decoded, and trailing slashes are removed. Callers that cache or compare normalized names may observe different strings after upgrading.
Migration: check for an empty result before sending the normalized resource name to the API.
APIError.Code is always the HTTP status
APIError.Code now comes from the HTTP response status rather than the JSON error.code field. IsBisectableDocumentError now requires the exact matched pairs 400 + INVALID_ARGUMENT or 404 + NOT_FOUND.
external_account credentials no longer require a quota project
Only authorized_user credentials require a quota project during client construction. external_account credentials can be used without one; when present, their quota_project_id is still honored.
Ambient CLOUDSDK_CONFIG errors are distinguished from absence
When the ADC file under CLOUDSDK_CONFIG exists, its bytes provide both the token source and quota-project metadata. Pure file absence continues to standard ADC discovery; permission failures, non-directory paths, dangling symlinks, malformed credentials, and other read errors are returned.
Additions
AuthConfig.AllowedOriginconfigures the only origin that a constructor-created authenticated client may contact.AuthConfig.QuotaProjectIDexplicitly configuresx-goog-user-projectand takes precedence overGOOGLE_CLOUD_QUOTA_PROJECTand credential-file metadata.
Fixes and hardening
- Token sources and quota-project metadata are derived from the same credential bytes, avoiding mixed credential sources.
- A custom
AuthConfig.TokenSourceno longer consultsCredentialsPathor ambient credential-file metadata. - Rejected transport requests close their request bodies without invoking the wrapped transport.
- Nil origins return an error instead of panicking.
CloseIdleConnectionsis delegated through the origin and quota-project transports.- Redirect callbacks are chained and revalidated after callback mutations.
- URL authority validation covers empty and out-of-range ports, non-canonical brackets, IPv6, Unicode case folding, userinfo, opaque URLs, and
Request.Hostoverrides. - CI asks
actions/setup-gofor the latest patch release beforegovulncheck, preventing stale hosted-toolcache versions from reintroducing fixed standard-library vulnerabilities.
Upgrade notes
Consumers upgrading directly from v0.1.x must also apply the context-first API migration documented in the v0.2.0 release notes.
go get github.com/apstndb/developerknowledge-go@v0.3.0Verification
go test -race ./...go vet ./...golangci-lint rungovulncheck ./...- GitHub Actions on Go 1.24 and Go 1.25
- Live v1
documents:batchGet: 20 names succeed; 21 names return400 INVALID_ARGUMENT, soMaxBatchGetDocumentsremains 20
Not included
- The open retry-policy expansion and
golang.org/x/oauth2update are not part of this release.
Full diff: v0.2.0...v0.3.0
Release notes updated 2026-07-13 to clarify normalization output and redirect behavior; the v0.3.0 tag is unchanged.
v0.2.0
Breaking changes
Context-first API
Client.Context has been removed. All request methods now take context.Context as their first parameter:
DoAPIRequest(ctx, method, reqURL, body, contentType)DoGet(ctx, reqURL)DoJSONPost(ctx, reqURL, body)BatchGetDocuments(ctx, names)
Migration for dependents (dkcli, gcp-docs-mirror-tools, spanner-mycli):
- Remove
Client.Contextfield assignment. - Pass
ctxas the first argument to everyClientmethod call. - If you previously relied on
Client.Contextfor cancellation/timeouts, pass that same context per call instead.
BatchGetDocuments validation
BatchGetDocuments now rejects empty name lists and more than MaxBatchGetDocuments (20) names per call. Use the new BatchGetDocumentsAll helper for larger lists (see below).
New features
MaxBatchGetDocumentsconstant — documents the API limit of 20 names perdocuments:batchGetcall.BatchGetDocumentsAll(ctx, names)— fetches documents in chunks ofMaxBatchGetDocumentswhile preserving input order.Document.ContentLengthBytes— new field mapped from the API'scontentLengthBytes.- Package documentation — added
doc.gowith godoc for thedkapipackage. - Agent instructions — added
AGENTS.md(referenced byCLAUDE.md) documenting module purpose, conventions, and verification commands. - CI workflow — GitHub Actions runs
go test -race,go vet,golangci-lint, andgovulncheckon Go 1.24 and 1.25. - Dependabot — weekly updates for Go modules and GitHub Actions.
- golangci-lint config —
.golangci.ymlwith errcheck, govet, staticcheck, and unused linters.
Fixes
CLOUDSDK_CONFIGADC resolution — whenCLOUDSDK_CONFIGorGOOGLE_APPLICATION_CREDENTIALSis set, or when the default ADC credentials file exists, token and quota-project metadata are read from that file instead of falling through to metadata-server ADC.external_accountquota project — ADC now requires a quota project forexternal_accountcredentials (in addition toauthorized_user), matchingauthorized_userbehavior.- Bounded error-body reads —
CheckResponselimits response body reads to 1 MiB for non-2xx and 429 responses, preventing unbounded memory use on error responses. NormalizeDocNamehardening — handles full URLs viaurl.Parse, strips query strings and fragments, removes trailing slashes, accepts uppercaseHTTP:///HTTPS://prefixes, and normalizes empty input todocuments/.
Documentation
- README — updated example for context-first API, documents
BatchGetDocumentsAll,CLOUDSDK_CONFIGsupport, bounded error reads, and links to pkg.go.dev.
Dependent repos
Open PRs in dkcli, spanner-mycli, and gcp-docs-mirror-tools that pin pseudo-versions of this module should update to:
go get github.com/apstndb/developerknowledge-go@v0.2.0Not included
PR #20 (expand retry policy beyond 429-only) remains open and is not part of this release.
v0.1.2
v0.1.1
Fixes
- Preserve the empty
urifield in serialized Document values for dkcli compatibility. - Parse HTTP-date
Retry-Aftervalues in addition to delay-seconds. - Treat any 2xx HTTP response as success.
- Make
Client.MaxRetriesmean additional retries after the first attempt and add coverage for one-retry behavior.
v0.1.0
Initial release.\n\n- Add API key and ADC authentication helpers.\n- Add quota project handling for local ADC.\n- Add Developer Knowledge API error and rate-limit parsing.\n- Add context-aware request helpers.\n- Add documents:batchGet support.\n- Add shared Document and DocumentChunk response types.\n- Add conservative batch bisection error classification.