Source File
details.go
Belonging Package
golang.org/x/pkgsite/internal/postgres
package postgres
import (
)
func ( *DB) ( context.Context, string) ( []*internal.ModuleInfo, error) {
defer derrors.WrapStack(&, "GetNestedModules(ctx, %v)", )
defer middleware.ElapsedStat(, "GetNestedModules")()
:= `
SELECT DISTINCT ON (series_path)
m.module_path,
m.version,
m.commit_time,
m.redistributable,
m.has_go_mod,
m.source_info
FROM
modules m
WHERE
m.module_path LIKE $1 || '/%'
ORDER BY
m.series_path,
m.incompatible,
m.version_type = 'release' DESC,
m.sort_version DESC;
`
var []*internal.ModuleInfo
:= func( *sql.Rows) error {
, := scanModuleInfo(.Scan)
if != nil {
return fmt.Errorf("rows.Scan(): %v", )
}
, := .IsExcluded(, .ModulePath)
if != nil {
return
}
if ! {
= append(, )
}
return nil
}
:= internal.SeriesPathForModule()
if := .db.RunQuery(, , , ); != nil {
return nil,
}
if := populateLatestInfos(, , ); != nil {
return nil,
}
return , nil
}
func ( *DB) ( context.Context, , string, int) ( []string, error) {
defer derrors.WrapStack(&, "GetImportedBy(ctx, %q, %q)", , )
defer middleware.ElapsedStat(, "GetImportedBy")()
if == "" {
return nil, fmt.Errorf("pkgPath cannot be empty: %w", derrors.InvalidArgument)
}
:= `
SELECT
DISTINCT from_path
FROM
imports_unique
WHERE
to_path = $1
AND
from_module_path <> $2
ORDER BY
from_path
LIMIT $3`
return collectStrings(, .db, , , , )
}
func ( *DB) ( context.Context, , string) ( int, error) {
defer derrors.WrapStack(&, "GetImportedByCount(ctx, %q, %q)", , )
defer middleware.ElapsedStat(, "GetImportedByCount")()
if == "" {
return 0, fmt.Errorf("pkgPath cannot be empty: %w", derrors.InvalidArgument)
}
:= `
SELECT imported_by_count
FROM
search_documents
WHERE
package_path = $1
`
var int
= .db.QueryRow(, , ).Scan(&)
switch {
case sql.ErrNoRows:
return 0, nil
case nil:
return , nil
default:
return 0,
}
}
func ( *DB) ( context.Context, , string) ( *internal.ModuleInfo, error) {
defer derrors.WrapStack(&, "GetModuleInfo(ctx, %q, %q)", , )
:= `
SELECT
module_path,
version,
commit_time,
redistributable,
has_go_mod,
source_info
FROM
modules
WHERE
module_path = $1
AND version = $2;`
:= .db.QueryRow(, , , )
, := scanModuleInfo(.Scan)
if == sql.ErrNoRows {
return nil, derrors.NotFound
}
if != nil {
return nil, fmt.Errorf("row.Scan(): %v", )
}
if := populateLatestInfo(, , ); != nil {
return nil,
}
return , nil
}
type jsonbScanner struct {
ptr interface{} // a pointer to a Go struct or other JSON-serializable value
}
func ( jsonbScanner) ( interface{}) ( error) {
defer derrors.Wrap(&, "jsonbScanner(%+v)", )
:= reflect.ValueOf(.ptr)
func ( func( ...interface{}) error) (*internal.ModuleInfo, error) {
var internal.ModuleInfo
if := (&.ModulePath, &.Version, &.CommitTime,
&.IsRedistributable, &.HasGoMod, jsonbScanner{&.SourceInfo}); != nil {
return nil,
}
return &, nil
}
var packageLinkRegexp = regexp.MustCompile(`(<a href="/)pkg/([^?#"]+)((?:#[^"]*)?">.*?</a>)`)
func ( string) string {
return packageLinkRegexp.ReplaceAllString(, `$1$2$3`)
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |