aboutsummaryrefslogtreecommitdiff
path: root/internal/fetchdatasource/fetchdatasource.go
diff options
context:
space:
mode:
authorEthan Lee <ethanalee@google.com>2026-03-11 21:08:19 +0000
committerGopher Robot <gobot@golang.org>2026-03-24 10:46:32 -0700
commit9da8f15f1c5721ddc1866bda9091a7f49c63fa10 (patch)
treecaa115cf134e6d93321dc671f0adfd85c6826a1a /internal/fetchdatasource/fetchdatasource.go
parent3619741c8e028c954fd53a4d554c3d4efe9a2356 (diff)
downloadgo-x-pkgsite-9da8f15f1c5721ddc1866bda9091a7f49c63fa10.tar.xz
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 <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> kokoro-CI: kokoro <noreply+kokoro@google.com> Auto-Submit: Ethan Lee <ethanalee@google.com> Reviewed-by: Jonathan Amsterdam <jba@google.com>
Diffstat (limited to 'internal/fetchdatasource/fetchdatasource.go')
-rw-r--r--internal/fetchdatasource/fetchdatasource.go29
1 files changed, 29 insertions, 0 deletions
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
+}