mirror of
https://github.com/dutchcoders/transfer.sh.git
synced 2025-01-09 02:20:18 +01:00
cb6e5cb0c7
* use dep for vendoring * lets encrypt * moved web to transfer.sh-web repo * single command install * added first tests
63 lines
1.4 KiB
Go
63 lines
1.4 KiB
Go
// Copyright 2013 The Go Authors. All rights reserved.
|
|
//
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file or at
|
|
// https://developers.google.com/open-source/licenses/bsd.
|
|
|
|
package gosrc
|
|
|
|
import (
|
|
"go/build"
|
|
"io/ioutil"
|
|
"path/filepath"
|
|
"strconv"
|
|
"time"
|
|
)
|
|
|
|
var localPath string
|
|
|
|
// SetLocalDevMode sets the package to local development mode. In this mode,
|
|
// the GOPATH specified by path is used to find directories instead of version
|
|
// control services.
|
|
func SetLocalDevMode(path string) {
|
|
localPath = path
|
|
}
|
|
|
|
func getLocal(importPath string) (*Directory, error) {
|
|
ctx := build.Default
|
|
if localPath != "" {
|
|
ctx.GOPATH = localPath
|
|
}
|
|
bpkg, err := ctx.Import(importPath, ".", build.FindOnly)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
dir := filepath.Join(bpkg.SrcRoot, filepath.FromSlash(importPath))
|
|
fis, err := ioutil.ReadDir(dir)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
var modTime time.Time
|
|
var files []*File
|
|
for _, fi := range fis {
|
|
if fi.IsDir() || !isDocFile(fi.Name()) {
|
|
continue
|
|
}
|
|
if fi.ModTime().After(modTime) {
|
|
modTime = fi.ModTime()
|
|
}
|
|
b, err := ioutil.ReadFile(filepath.Join(dir, fi.Name()))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
files = append(files, &File{
|
|
Name: fi.Name(),
|
|
Data: b,
|
|
})
|
|
}
|
|
return &Directory{
|
|
ImportPath: importPath,
|
|
Etag: strconv.FormatInt(modTime.Unix(), 16),
|
|
Files: files,
|
|
}, nil
|
|
}
|