From 9da8f15f1c5721ddc1866bda9091a7f49c63fa10 Mon Sep 17 00:00:00 2001 From: Ethan Lee Date: Wed, 11 Mar 2026 21:08:19 +0000 Subject: internal/api: implement module packages endpoint - Implement the ServeModulePackages handler and introduce GetModulePackages to return the list of packages for a given module version. Change-Id: I20c1618e2fdbf0126cb913665a1d7457b8951177 Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/754863 LUCI-TryBot-Result: Go LUCI kokoro-CI: kokoro Auto-Submit: Ethan Lee Reviewed-by: Jonathan Amsterdam --- internal/fetchdatasource/fetchdatasource.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'internal/fetchdatasource/fetchdatasource.go') diff --git a/internal/fetchdatasource/fetchdatasource.go b/internal/fetchdatasource/fetchdatasource.go index 41573ae5..1643d009 100644 --- a/internal/fetchdatasource/fetchdatasource.go +++ b/internal/fetchdatasource/fetchdatasource.go @@ -404,3 +404,32 @@ func (ds *FetchDataSource) Search(ctx context.Context, q string, opts internal.S return results, nil } + +// GetModulePackages returns a list of packages in the given module version. +func (ds *FetchDataSource) GetModulePackages(ctx context.Context, modulePath, version string) ([]*internal.PackageMeta, error) { + m, err := ds.getModule(ctx, modulePath, version) + if err != nil { + return nil, err + } + var metas []*internal.PackageMeta + for _, um := range m.UnitMetas { + if um.IsPackage() { + u, err := ds.findUnit(ctx, m, um.Path) + if err != nil { + return nil, err + } + var synopsis string + if len(u.Documentation) > 0 { + synopsis = u.Documentation[0].Synopsis + } + metas = append(metas, &internal.PackageMeta{ + Path: u.Path, + Name: u.Name, + Synopsis: synopsis, + IsRedistributable: u.IsRedistributable, + Licenses: u.Licenses, + }) + } + } + return metas, nil +} -- cgit v1.3