Source File
stdlib.go
Belonging Package
golang.org/x/pkgsite/internal/stdlib
package stdlib
import (
)
const ModulePath = "std"
tagRegexp = regexp.MustCompile(`^go(\d+\.\d+)(\.\d+|)((beta|rc)(\d+))?$`)
)
if == "go1" {
return "v1.0.0"
}
if == "go1.0" {
return ""
if == "latest" || == "master" {
return
}
:= tagRegexp.FindStringSubmatch()
if == nil {
return ""
}
:= "v" + [1]
if [2] != "" {
+= [2]
} else {
+= ".0"
}
if [3] != "" {
+= "-" + [4] + "." + [5]
}
return
}
if == "v1.0.0" {
return "go1", nil
}
if !semver.IsValid() {
return "", fmt.Errorf("%w: requested version is not a valid semantic version: %q ", derrors.InvalidArgument, )
}
:= semver.Canonical()
:= semver.Prerelease()
:= strings.TrimSuffix(, )
:= strings.TrimPrefix(, semver.MajorMinor()+".")
if == "0" {
= strings.TrimSuffix(, ".0")
}
= fmt.Sprintf("go%s", strings.TrimPrefix(, "v"))
:= finalDigitsIndex()
if >= 1 {
if [-1] != '.' {
return "", fmt.Errorf("%w: final digits in a prerelease must follow a period", derrors.InvalidArgument)
= [:-1] + [:]
}
+= strings.TrimPrefix(, "-")
}
return , nil
}
var int
for = len() - 1; >= 0; -- {
if [] < '0' || [] > '9' {
break
}
}
if == len()-1 {
return -1
}
return + 1
}
const (
GoRepoURL = "https://go.googlesource.com/go"
GoSourceRepoURL = "https://cs.opensource.google/go/go"
)
var UseTestData = false
var (
TestCommitTime = time.Date(2019, 9, 4, 1, 2, 3, 0, time.UTC)
TestVersion = "v0.0.0-20190904010203-89fb59e2e920"
)
func ( string) ( *git.Repository, error) {
defer derrors.Wrap(&, "getGoRepo(%q)", )
var plumbing.ReferenceName
if == "master" {
= plumbing.HEAD
} else {
, := TagForVersion()
if != nil {
return nil,
}
= plumbing.NewTagReferenceName()
}
return git.Clone(memory.NewStorage(), nil, &git.CloneOptions{
URL: GoRepoURL,
ReferenceName: ,
SingleBranch: true,
Depth: 1,
Tags: git.NoTags,
})
}
func ( string) ( *git.Repository, error) {
defer derrors.Wrap(&, "getTestGoRepo(%q)", )
if strings.HasPrefix(, "v0.0.0") {
= "master"
}
:= osfs.New(filepath.Join(testhelper.TestDataPath("testdata"), ))
, := git.Init(memory.NewStorage(), )
if != nil {
return nil,
}
, := .Worktree()
if != nil {
return nil,
func () ( []string, error) {
defer derrors.Wrap(&, "Versions()")
var []plumbing.ReferenceName
if UseTestData {
= testRefs
} else {
:= git.NewRemote(memory.NewStorage(), &config.RemoteConfig{
URLs: []string{GoRepoURL},
})
, := .List(&git.ListOptions{})
if != nil {
return nil, fmt.Errorf("re.List: %v", )
}
for , := range {
= append(, .Name())
}
}
var []string
for , := range {
:= VersionForTag(.Short())
if != "" {
= append(, )
}
}
return , nil
}
return "src/pkg"
}
const EstimatedZipSize = 16 * 1024 * 1024
defer derrors.Wrap(&, "stdlib.Zip(%q)", )
var *git.Repository
if UseTestData {
, = getTestGoRepo()
} else {
, = getGoRepo()
}
if != nil {
return nil, "", time.Time{},
}
var bytes.Buffer
:= zip.NewWriter(&)
, := .Head()
if != nil {
return nil, "", time.Time{},
}
, := .CommitObject(.Hash())
if != nil {
return nil, "", time.Time{},
}
if == "master" {
= newPseudoVersion("v0.0.0", .Committer.When, .Hash)
}
, := .TreeObject(.TreeHash)
if != nil {
return nil, "", time.Time{},
}
:=
for , := range strings.Split(Directory(), "/") {
, = subTree(, , )
if != nil {
return nil, "", time.Time{},
}
}
if := addFiles(, , , , true); != nil {
return nil, "", time.Time{},
}
if := .Close(); != nil {
return nil, "", time.Time{},
}
:= bytes.NewReader(.Bytes())
, := zip.NewReader(, int64(.Len()))
if != nil {
return nil, "", time.Time{},
}
return , , .Committer.When, nil
}
func ( string, time.Time, plumbing.Hash) string {
return fmt.Sprintf("%s-%s-%s", , .Format("20060102150405"), .String()[:12])
}
func ( string) ( string, error) {
defer derrors.Wrap(&, "semanticVersion(%q)", )
if == "master" {
return "master", nil
}
, := Versions()
if != nil {
return "",
}
switch {
case "latest":
var string
for , := range {
if !strings.HasPrefix(, "v") {
continue
}
, := version.ParseType()
if != nil {
return "",
}
continue
}
continue
}
switch .Mode {
case filemode.Regular, filemode.Executable:
, := .BlobObject(.Hash)
if != nil {
return
}
, := .Reader()
if != nil {
return
}
if := writeZipFile(, path.Join(, .Name), ); != nil {
_ = .Close()
return
}
if := .Close(); != nil {
return
}
case filemode.Dir:
if ! || .Name == "testdata" {
continue
}
, := .TreeObject(.Hash)
if != nil {
return
}
if := (, , , path.Join(, .Name), ); != nil {
return
}
}
}
return nil
}
func ( *zip.Writer, string, io.Reader) ( error) {
defer derrors.Wrap(&, "writeZipFile(zip, %q, src)", )
, := .Create()
if != nil {
return
}
_, = io.Copy(, )
return
}
"refs/tags/go1.2.1",
"refs/tags/go1.3.2",
"refs/tags/go1.4.2",
"refs/tags/go1.4.3",
"refs/tags/go1.6",
"refs/tags/go1.6.3",
"refs/tags/go1.6beta1",
"refs/tags/go1.8",
"refs/tags/go1.8rc2",
"refs/tags/go1.9rc1",
"refs/tags/go1.11",
"refs/tags/go1.12",
"refs/tags/go1.12.1",
"refs/tags/go1.12.5",
"refs/tags/go1.12.9",
"refs/tags/go1.13",
"refs/tags/go1.13beta1",
"refs/tags/go1.14.6",
"refs/changes/56/93156/13",
"refs/tags/release.r59",
"refs/tags/weekly.2011-04-13",
![]() |
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. |