Source File
fetchlocal.go
Belonging Package
golang.org/x/pkgsite/internal/fetch
package fetch
import (
)
var (
LocalVersion = "v0.0.0"
LocalCommitTime = time.Time{}
)
func ( context.Context, , string, *source.Client) *FetchResult {
:= &FetchResult{
ModulePath: ,
RequestedVersion: LocalVersion,
ResolvedVersion: LocalVersion,
Defer: func() {},
}
var *FetchInfo
defer func() {
if .Error != nil {
derrors.Wrap(&.Error, "FetchLocalModule(%q, %q)", , )
.Status = derrors.ToStatus(.Error)
}
if .Status == 0 {
.Status = http.StatusOK
}
if != nil {
finishFetchInfo(, .Status, .Error)
}
}()
, := os.Stat()
if != nil {
.Error = fmt.Errorf("%s: %w", .Error(), derrors.NotFound)
return
}
if !.IsDir() {
.Error = fmt.Errorf("%s not a directory: %w", , derrors.NotFound)
return
}
= &FetchInfo{
ModulePath: .ModulePath,
Version: .ResolvedVersion,
Start: time.Now(),
}
startFetchInfo()
if , := ioutil.ReadFile(filepath.Join(, "go.mod")); != nil {
.GoModPath =
.HasGoMod = false
} else {
.HasGoMod = true
.GoModPath = modfile.ModulePath()
if .GoModPath != && != "" {
.Error = fmt.Errorf("module path=%s, go.mod path=%s: %w", , .GoModPath, derrors.AlternativeModule)
return
}
}
if .GoModPath == "" {
.Error = fmt.Errorf("no module path: %w", derrors.BadModule)
return
}
.ModulePath = .GoModPath
, := createZipReader(, .GoModPath, LocalVersion)
if != nil {
.Error = fmt.Errorf("couldn't create a zip: %s, %w", .Error(), derrors.BadModule)
return
}
, , := processZipFile(, .GoModPath, LocalVersion, LocalCommitTime, , )
if != nil {
.Error =
return
}
.HasGoMod = .HasGoMod
.Module =
.PackageVersionStates =
.Module.SourceInfo = nil // version is not known, so even if info is found it most likely is wrong.
for , := range .PackageVersionStates {
if .Status != http.StatusOK {
.Status = derrors.ToStatus(derrors.HasIncompletePackages)
}
}
return
}
func (, , string) (*zip.Reader, error) {
:= new(bytes.Buffer)
:= zip.NewWriter()
:= filepath.Walk(, func( string, os.FileInfo, error) error {
if != nil {
return
}
if .IsDir() {
return nil
}
, := os.Open()
if != nil {
return
}
defer .Close()
, := .Create(filepath.Join(moduleVersionDir(, ), strings.TrimPrefix(, )))
if != nil {
return
}
_, = io.Copy(, )
return
})
if != nil {
return nil,
}
if := .Close(); != nil {
return nil,
}
:= bytes.NewReader(.Bytes())
return zip.NewReader(, .Size())
![]() |
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. |