diff --git a/internal/discovery.go b/internal/discovery.go index 04365544..0b33d963 100644 --- a/internal/discovery.go +++ b/internal/discovery.go @@ -46,6 +46,7 @@ type Package struct { Path string Name string Synopsis string + Suffix string // if my.module/v2/A/B is the path, A/B is the package suffix Version *Version } diff --git a/internal/fetch/fetch.go b/internal/fetch/fetch.go index 81499c0f..d61d2835 100644 --- a/internal/fetch/fetch.go +++ b/internal/fetch/fetch.go @@ -67,9 +67,9 @@ func parseVersion(version string) (internal.VersionType, error) { prerelease = prerelease[1:] // remove starting dash // if prerelease looks like a commit then return VersionTypePseudo - matched, err := regexp.MatchString(`[0-9]{14}-[0-9a-z]{12}`, prerelease) + matched, err := regexp.MatchString(`^[0-9]{14}-[0-9a-z]{12}$`, prerelease) if err != nil { - return "", fmt.Errorf("regexp.MatchString(`[0-9]{14}-[0-9a-z]{12}`, %v): %v", prerelease, err) + return "", fmt.Errorf("regexp.MatchString(`^[0-9]{14}-[0-9a-z]{12}$`, %v): %v", prerelease, err) } if matched { @@ -229,6 +229,7 @@ func extractPackagesFromZip(module, version string, r *zip.Reader) ([]*internal. Name: p.Name, Path: p.PkgPath, Synopsis: doc.Synopsis(d.Doc), + Suffix: strings.TrimPrefix(strings.TrimPrefix(p.PkgPath, module), "/"), }) } return packages, nil diff --git a/internal/postgres/postgres.go b/internal/postgres/postgres.go index 0947dcc5..8065fcf4 100644 --- a/internal/postgres/postgres.go +++ b/internal/postgres/postgres.go @@ -496,15 +496,15 @@ func (db *DB) InsertVersion(version *internal.Version) error { } stmt, err := tx.Prepare( - `INSERT INTO packages (path, synopsis, name, version, module_path, version_type) - VALUES ($1, $2, $3, $4, $5, $6) ON CONFLICT DO NOTHING`) + `INSERT INTO packages (path, synopsis, name, version, module_path, version_type, suffix) + VALUES ($1, $2, $3, $4, $5, $6, $7) ON CONFLICT DO NOTHING`) if err != nil { return fmt.Errorf("error preparing package stmt: %v", err) } defer stmt.Close() for _, p := range version.Packages { - if _, err = stmt.Exec(p.Path, p.Synopsis, p.Name, version.Version, version.Module.Path, version.VersionType.String()); err != nil { + if _, err = stmt.Exec(p.Path, p.Synopsis, p.Name, version.Version, version.Module.Path, version.VersionType.String(), p.Suffix); err != nil { return fmt.Errorf("error inserting package: %v", err) } }