Skip to content

Commit

Permalink
internal/mod/modregistry: add Module.Version method
Browse files Browse the repository at this point in the history
This makes the API slightly more ergonomic, avoiding
the need for callers to pass the `*Module` around with
its corresponding version.

Signed-off-by: Roger Peppe <[email protected]>
Change-Id: I40496445fc75cbb18096b31eb703a94570b2ddbd
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1173787
TryBot-Result: CUEcueckoo <[email protected]>
Unity-Result: CUE porcuepine <[email protected]>
Reviewed-by: Daniel Martí <[email protected]>
  • Loading branch information
rogpeppe committed Dec 18, 2023
1 parent 414695f commit 72766c2
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions internal/mod/modregistry/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ func (c *Client) GetModuleWithManifest(ctx context.Context, m module.Version, co
// TODO check that the other blobs are of the expected type (application/zip).
return &Module{
client: c,
version: m,
repo: repoName,
manifest: *manifest,
manifestDigest: digest.FromBytes(contents),
Expand Down Expand Up @@ -313,10 +314,15 @@ func checkModFile(m module.Version, f *zip.File) ([]byte, *modfile.File, error)
type Module struct {
client *Client
repo string
version module.Version
manifest ocispec.Manifest
manifestDigest ociregistry.Digest
}

func (m *Module) Version() module.Version {
return m.version
}

// ModuleFile returns the contents of the cue.mod/module.cue file.
func (m *Module) ModuleFile(ctx context.Context) ([]byte, error) {
r, err := m.client.registry.GetBlob(ctx, m.repo, m.manifest.Layers[1].Digest)
Expand Down

0 comments on commit 72766c2

Please sign in to comment.