From 06c847e1184d477cfb622ff6710b48848bf0ffcf Mon Sep 17 00:00:00 2001 From: Ethan Lee Date: Wed, 11 Mar 2026 21:17:12 +0000 Subject: internal/api: implement package symbols endpoint - Introduce a new ServePackageSymbols handler that utilizes the new db.GetSymbols method. - Consolidated module resolution logic shared by ServePackages into resolveModulePath. - Updated Datasource with GetSymbols, which provides a more efficient way to retrieve all symbols for a package at a given version and build context. This differs from the existing getPackageSymbols, since that will return symbols for the latest release/compatible version. - Refactored packageSymbolQueryJoin into a generic helper by removing hardcoded version filters. This allows GetSymbols to query for any specific version, while getPackageSymbols was updated to explicitly include release-only filters to preserve its existing behavior. - GetSymbols still utilizes the same underlying packageSymbolQueryJoin, but it will also attempt to match the most relevant BuildContext for the query. It will also provide a mapping of parent and child symbols. Change-Id: Ib18d2511d24ac6bc5b75c7b3809c4ce126245036 Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/754864 Auto-Submit: Ethan Lee kokoro-CI: kokoro Reviewed-by: Jonathan Amsterdam LUCI-TryBot-Result: Go LUCI --- internal/fetchdatasource/fetchdatasource.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'internal/fetchdatasource/fetchdatasource.go') diff --git a/internal/fetchdatasource/fetchdatasource.go b/internal/fetchdatasource/fetchdatasource.go index 1643d009..7a5f5669 100644 --- a/internal/fetchdatasource/fetchdatasource.go +++ b/internal/fetchdatasource/fetchdatasource.go @@ -433,3 +433,23 @@ func (ds *FetchDataSource) GetModulePackages(ctx context.Context, modulePath, ve } return metas, nil } + +// GetSymbols returns symbols for the given unit and build context. +func (ds *FetchDataSource) GetSymbols(ctx context.Context, pkgPath, modulePath, version string, bc internal.BuildContext) (_ []*internal.Symbol, err error) { + defer derrors.Wrap(&err, "FetchDataSource.GetSymbols(%q, %q, %q, %v)", pkgPath, modulePath, version, bc) + + m, err := ds.getModule(ctx, modulePath, version) + if err != nil { + return nil, err + } + unit, err := ds.findUnit(ctx, m, pkgPath) + if err != nil { + return nil, err + } + + doc := matchingDoc(unit.Documentation, bc) + if doc == nil || len(doc.API) == 0 { + return nil, derrors.NotFound + } + return doc.API, nil +} -- cgit v1.3-5-g45d5