Source File
sample.go
Belonging Package
golang.org/x/pkgsite/internal/testing/sample
package sample
import (
oldlicensecheck
)
var (
ModulePath = "github.com/valid/module_name"
RepositoryURL = "https://github.com/valid/module_name"
VersionString = "v1.0.0"
CommitTime = NowTruncated()
LicenseType = "MIT"
LicenseFilePath = "LICENSE"
NonRedistributableLicense = &licenses.License{
Metadata: &licenses.Metadata{
FilePath: "NONREDIST_LICENSE",
Types: []string{"UNKNOWN"},
},
Contents: []byte(`unknown`),
}
PackageName = "foo"
Suffix = "foo"
PackagePath = path.Join(ModulePath, Suffix)
V1Path = PackagePath
ReadmeFilePath = "README.md"
ReadmeContents = "readme"
GOOS = internal.All
GOARCH = internal.All
Doc = Documentation(GOOS, GOARCH, DocContents)
API = []*internal.Symbol{
{
SymbolMeta: internal.SymbolMeta{
Name: "V",
ParentName: "V",
Synopsis: "var V int",
Section: internal.SymbolSectionVariables,
Kind: internal.SymbolKindVariable,
},
GOOS: GOOS,
GOARCH: GOARCH,
},
}
DocContents = `
// Package p is a package.
//
//
// Links
//
// - pkg.go.dev, https://pkg.go.dev
package p
var V int
`
Constant = &internal.Symbol{
SymbolMeta: internal.SymbolMeta{
Name: "Constant",
Synopsis: "const Constant",
Section: internal.SymbolSectionConstants,
Kind: internal.SymbolKindConstant,
},
GOOS: internal.All,
GOARCH: internal.All,
}
Variable = &internal.Symbol{
SymbolMeta: internal.SymbolMeta{
Name: "Variable",
Synopsis: "var Variable",
Section: internal.SymbolSectionVariables,
Kind: internal.SymbolKindVariable,
},
GOOS: internal.All,
GOARCH: internal.All,
}
Function = &internal.Symbol{
SymbolMeta: internal.SymbolMeta{
Name: "Function",
Synopsis: "func Function() error",
Section: internal.SymbolSectionFunctions,
Kind: internal.SymbolKindFunction,
},
GOOS: internal.All,
GOARCH: internal.All,
}
FunctionNew = &internal.Symbol{
SymbolMeta: internal.SymbolMeta{
Name: "New",
Synopsis: "func New() *Type",
Section: internal.SymbolSectionTypes,
Kind: internal.SymbolKindFunction,
ParentName: "Type",
},
GOOS: internal.All,
GOARCH: internal.All,
}
Type = &internal.Symbol{
SymbolMeta: internal.SymbolMeta{
Name: "Type",
Synopsis: "type Type struct",
Section: internal.SymbolSectionTypes,
Kind: internal.SymbolKindType,
},
GOOS: internal.All,
GOARCH: internal.All,
Children: []*internal.SymbolMeta{
func() *internal.SymbolMeta {
:= FunctionNew.SymbolMeta
return &
}(),
{
Name: "Type.Field",
Synopsis: "field",
Section: internal.SymbolSectionTypes,
Kind: internal.SymbolKindField,
ParentName: "Type",
},
{
Name: "Type.Method",
Synopsis: "method",
Section: internal.SymbolSectionTypes,
Kind: internal.SymbolKindMethod,
ParentName: "Type",
},
},
}
)
var LicenseCmpOpts = []cmp.Option{
cmp.Comparer(coveragePercentEqual),
cmpopts.IgnoreFields(licensecheck.Match{}, "Start", "End"),
}
func () time.Time {
return time.Now().In(time.UTC).Truncate(time.Microsecond)
}
func () *internal.Module {
:= constructFullPath(ModulePath, Suffix)
return AddPackage(Module(ModulePath, VersionString), UnitForPackage(, ModulePath, VersionString, path.Base(), true))
}
func (, string, ...string) *internal.Module {
:= ModuleInfo(, )
:= &internal.Module{
ModuleInfo: *,
Licenses: Licenses(),
}
.Units = []*internal.Unit{UnitForModuleRoot()}
for , := range {
:= constructFullPath(, )
:= UnitForPackage(, , VersionString, path.Base(), .IsRedistributable)
if != "" {
AddPackage(, )
} else {
:= UnitForPackage(.Path, , , .Name, .IsRedistributable)
.Units[0].Documentation = .Documentation
.Units[0].Name = .Name
}
}
if == stdlib.ModulePath {
.Units[0].Readme = nil
for , := range .Units {
.LicenseContents = .Licenses
}
return
}
func ( *internal.ModuleInfo) *internal.Unit {
:= &internal.Unit{
UnitMeta: *UnitMeta(.ModulePath, .ModulePath, .Version, "", .IsRedistributable),
LicenseContents: Licenses(),
}
.Readme = &internal.Readme{
Filepath: ReadmeFilePath,
Contents: ReadmeContents,
}
return
}
:= *Doc
:= Imports()
return &internal.Unit{
UnitMeta: *UnitMeta(, , , , ),
Documentation: []*internal.Documentation{&},
LicenseContents: Licenses(),
Imports: ,
NumImports: len(),
}
}
func ( *internal.Module, *internal.Unit) *internal.Module {
if .ModulePath != stdlib.ModulePath && !strings.HasPrefix(.Path, .ModulePath) {
panic(fmt.Sprintf("package path %q not a prefix of module path %q",
.Path, .ModulePath))
}
AddUnit(, UnitForPackage(.Path, .ModulePath, .Version, .Name, .IsRedistributable))
:= len(.ModulePath)
if .ModulePath == stdlib.ModulePath {
= 1
}
for := .Path; len() > ; = path.Dir() {
:= false
for , := range .Units {
if .Path == {
= true
break
}
}
if ! {
AddUnit(, UnitEmpty(, .ModulePath, .Version))
}
}
return
}
func ( string) *internal.PackageMeta {
return &internal.PackageMeta{
Path: ,
IsRedistributable: true,
Name: path.Base(),
Synopsis: Doc.Synopsis,
Licenses: LicenseMetadata(),
}
}
func (, string) *internal.ModuleInfo {
return &internal.ModuleInfo{
ModulePath: ,
Version: ,
SourceInfo: source.NewGitHubInfo("https://"+, "", ),
IsRedistributable: true,
HasGoMod: true,
}
}
func () *internal.VersionMap {
return &internal.VersionMap{
ModulePath: ModulePath,
RequestedVersion: VersionString,
ResolvedVersion: VersionString,
Status: http.StatusOK,
GoModPath: "",
Error: "",
}
}
func ( *internal.Module, *internal.Unit) {
for , := range .Units {
if .Path == .Path {
panic(fmt.Sprintf("module already has path %q", .Path))
}
}
.Units = append(.Units, )
}
func ( *internal.Module, *licenses.License) {
.Licenses = append(.Licenses, )
:= path.Dir(.FilePath)
if == "." {
= ""
}
for , := range .Units {
if strings.TrimPrefix(.Path, .ModulePath+"/") == {
.Licenses = append(.Licenses, .Metadata)
.LicenseContents = append(.LicenseContents, )
}
}
}
func ( *internal.Module, *licenses.License) {
replaceLicense(, .Licenses)
for , := range .Units {
for , := range .Licenses {
if .FilePath == .FilePath {
.Licenses[] = .Metadata
}
}
replaceLicense(, .LicenseContents)
}
}
func ( *licenses.License, []*licenses.License) {
for , := range {
if .FilePath == .FilePath {
[] =
}
}
}
func (, , string) *internal.Unit {
return &internal.Unit{
UnitMeta: *UnitMeta(, , , "", true),
}
}
func (, , , string, bool) *internal.UnitMeta {
return &internal.UnitMeta{
Path: ,
Name: ,
IsRedistributable: ,
Licenses: LicenseMetadata(),
ModuleInfo: internal.ModuleInfo{
ModulePath: ,
Version: ,
CommitTime: NowTruncated(),
IsRedistributable: ,
SourceInfo: source.NewGitHubInfo("https://"+, "", ),
},
}
}
func (, string) string {
if != stdlib.ModulePath {
return path.Join(, )
}
return
}
func (, , string) *internal.Documentation {
:= token.NewFileSet()
, := parser.ParseFile(, "sample.go", , parser.ParseComments)
if != nil {
panic()
}
:= godoc.NewPackage(, nil)
.AddFile(, true)
, := .Encode(context.Background())
if != nil {
panic()
}
return &internal.Documentation{
GOOS: ,
GOARCH: ,
Synopsis: fmt.Sprintf("This is a package synopsis for GOOS=%s, GOARCH=%s", , ),
Source: ,
}
}
func () []*licenses.Metadata {
return []*licenses.Metadata{
{
Types: []string{LicenseType},
FilePath: LicenseFilePath,
OldCoverage: oldlicensecheck.Coverage{
Percent: 100,
Match: []oldlicensecheck.Match{{Name: LicenseType, Type: oldlicensecheck.MIT, Percent: 100}},
},
},
}
}
func () []*licenses.License {
return []*licenses.License{
{Metadata: LicenseMetadata()[0], Contents: []byte(`Lorem Ipsum`)},
}
}
func () []string {
return []string{"fmt", "path/to/bar"}
![]() |
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. |