本文整理汇总了Golang中go/build.Import函数的典型用法代码示例。如果您正苦于以下问题:Golang Import函数的具体用法?Golang Import怎么用?Golang Import使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Import函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: parsePatterns
func parsePatterns(pkgPatterns ...string) (packages []string) {
for _, pkgPattern := range pkgPatterns {
if !strings.HasSuffix(pkgPattern, "...") {
packages = append(packages, pkgPattern)
continue
}
parent := strings.TrimSuffix(pkgPattern, "...")
parentPkg, err := build.Import(parent, cwd, build.AllowBinary)
if err != nil {
panic(err)
}
filepath.Walk(parentPkg.Dir, func(path string, info os.FileInfo, err error) error {
if !info.IsDir() {
return nil
}
path = strings.Replace(path, parentPkg.Dir, parent, 1)
if _, err := build.Import(path, cwd, build.AllowBinary); err != nil {
// This directory doesn't appear to be a go package
return nil
}
packages = append(packages, path)
return nil
})
}
return
}
开发者ID:nelsam,项目名称:hel,代码行数:26,代码来源:packages.go
示例2: newApp
func newApp(args []string) {
if len(args) == 0 {
errorf("No path given.\nRun 'revel help new' for usage.\n")
}
importPath := args[0]
_, err := build.Import(importPath, "", build.FindOnly)
if err == nil {
fmt.Fprintf(os.Stderr, "Abort: Import path %s already exists.\n", importPath)
return
}
revelPkg, err := build.Import("github.com/robfig/revel", "", build.FindOnly)
if err != nil {
fmt.Fprintln(os.Stderr, "Failed to find revel code.")
return
}
appDir := path.Join(revelPkg.SrcRoot, filepath.FromSlash(importPath))
err = os.MkdirAll(appDir, 0777)
panicOnError(err, "Failed to create directory "+appDir)
skeletonBase = path.Join(revelPkg.Dir, "skeleton")
mustCopyDir(appDir, skeletonBase, map[string]interface{}{
// app.conf
"AppName": filepath.Base(appDir),
"Secret": genSecret(),
})
fmt.Fprintln(os.Stdout, "Your application is ready:\n ", appDir)
fmt.Fprintln(os.Stdout, "\nYou can run it with:\n revel run", importPath)
}
开发者ID:pmlarocque,项目名称:revel,代码行数:32,代码来源:new.go
示例3: setApplicationPath
func setApplicationPath(args []string) {
var err error
importPath = args[0]
if filepath.IsAbs(importPath) {
errorf("Abort: '%s' looks like a directory. Please provide a Go import path instead.",
importPath)
}
_, err = build.Import(importPath, "", build.FindOnly)
if err == nil {
errorf("Abort: Import path %s already exists.\n", importPath)
}
revelPkg, err = build.Import(revel.REVEL_IMPORT_PATH, "", build.FindOnly)
if err != nil {
errorf("Abort: Could not find Revel source code: %s\n", err)
}
appPath = filepath.Join(srcRoot, filepath.FromSlash(importPath))
appName = filepath.Base(appPath)
basePath = filepath.ToSlash(filepath.Dir(importPath))
if basePath == "." {
// we need to remove the a single '.' when
// the app is in the $GOROOT/src directory
basePath = ""
} else {
// we need to append a '/' when the app is
// is a subdirectory such as $GOROOT/src/path/to/revelapp
basePath += "/"
}
}
开发者ID:huaguzi,项目名称:revel,代码行数:32,代码来源:new.go
示例4: genMath
// genMath generates the standard math package.
func genMath() error {
log.Println("Generating math package")
// XXX currently just copying the already-generated Go files from the
// standard library. We'll need to either translate the assembly files
// (manually or automatically), or perhaps use compiler-rt.
gopkg, err := build.Import("math", "", 0)
if err != nil {
return err
}
const llgopkgpath = "github.com/axw/llgo/pkg/math"
llgopkg, err := build.Import(llgopkgpath, "", build.FindOnly)
if err != nil {
return err
}
for _, filename := range gopkg.GoFiles {
srcfile := filepath.Join(gopkg.Dir, filename)
data, err := ioutil.ReadFile(srcfile)
if err != nil {
return err
}
dstfile := filepath.Join(llgopkg.Dir, filename)
err = ioutil.WriteFile(dstfile, data, os.FileMode(0644))
if err != nil {
return err
}
log.Printf("- %s", filename)
}
return nil
}
开发者ID:kelsieflynn,项目名称:llgo,代码行数:35,代码来源:genmath.go
示例5: genSyscall
// genSyscall generates the standard syscall package.
func genSyscall() error {
log.Println("Generating syscall package")
// XXX currently just copying the already-generated Go files from the
// standard library. In the future, we'll just copy the handwritten
// bits and generate the other stuff using a pure-Go package.
gopkg, err := build.Import("syscall", "", 0)
if err != nil {
return err
}
const llgopkgpath = "github.com/axw/llgo/pkg/syscall"
llgopkg, err := build.Import(llgopkgpath, "", build.FindOnly)
if err != nil {
return err
}
for _, filename := range gopkg.GoFiles {
srcfile := filepath.Join(gopkg.Dir, filename)
data, err := ioutil.ReadFile(srcfile)
if err != nil {
return err
}
dstfile := filepath.Join(llgopkg.Dir, filename)
err = ioutil.WriteFile(dstfile, data, os.FileMode(0644))
if err != nil {
return err
}
log.Printf("- %s", filename)
}
return nil
}
开发者ID:kelsieflynn,项目名称:llgo,代码行数:35,代码来源:gensyscall.go
示例6: findSrcPaths
// findSrcPaths uses the "go/build" package to find the source root for Revel
// and the app.
func findSrcPaths(importPath string) (revelSourcePath, appSourcePath string) {
var (
gopaths = filepath.SplitList(build.Default.GOPATH)
goroot = build.Default.GOROOT
)
if len(gopaths) == 0 {
ERROR.Fatalln("GOPATH environment variable is not set. ",
"Please refer to http://golang.org/doc/code.html to configure your Go environment.")
}
if ContainsString(gopaths, goroot) {
ERROR.Fatalf("GOPATH (%s) must not include your GOROOT (%s). "+
"Please refer to http://golang.org/doc/code.html to configure your Go environment.",
gopaths, goroot)
}
appPkg, err := build.Import(importPath, "", build.FindOnly)
if err != nil {
ERROR.Fatalln("Failed to import", importPath, "with error:", err)
}
revelPkg, err := build.Import(REVEL_IMPORT_PATH, "", build.FindOnly)
if err != nil {
ERROR.Fatalln("Failed to find Revel with error:", err)
}
return revelPkg.SrcRoot, appPkg.SrcRoot
}
开发者ID:jlujan,项目名称:revel,代码行数:31,代码来源:revel.go
示例7: setAppPaths
func setAppPaths(args []string) {
var err error
importPath := args[0]
if filepath.IsAbs(importPath) {
errorf("Abort: '%s' looks like a directory. Please provide a Go import path instead.", importPath)
}
_, err = build.Import(importPath, "", build.FindOnly)
if err == nil {
errorf("Abort: Import path %s already exists.\n", importPath)
}
armadilloPkg, err2 := build.Import(IMPORT_PATH, "", build.FindOnly)
if err2 != nil {
errorf("Abort: Could not find Armadillo source code: %s\n", err)
}
appPath = filepath.Join(srcRoot, filepath.FromSlash(importPath))
appName = filepath.Base(appPath)
skeletonPath = filepath.Join(armadilloPkg.Dir, "skeleton")
templateData = map[string]interface{}{
"AppName": appName,
}
}
开发者ID:repp,项目名称:armadillo,代码行数:25,代码来源:cmd_new.go
示例8: buildLlgo
func buildLlgo() error {
log.Println("Building llgo")
pkg, err := build.Import(gollvmpkgpath, "", build.FindOnly)
if err != nil {
return err
}
cgoCflags := fmt.Sprintf("%s -I %s/../include", llvmcflags, pkg.Dir)
cgoLdflags := fmt.Sprintf("%s -Wl,-L%s -lLLVM-%s",
llvmldflags, llvmlibdir, llvmversion)
var output []byte
ldflags := "-r " + llvmlibdir
args := []string{"get", "-ldflags", ldflags}
llvmtag := "llvm" + llvmversion
if strings.HasSuffix(llvmversion, "svn") {
llvmtag = "llvmsvn"
}
args = append(args, []string{"-tags", llvmtag}...)
args = append(args, llgopkgpath)
cmd := exec.Command("go", args...)
cmd.Env = os.Environ()
cmd.Env = append(cmd.Env, "CGO_CFLAGS="+cgoCflags)
cmd.Env = append(cmd.Env, "CGO_LDFLAGS="+cgoLdflags)
output, err = cmd.CombinedOutput()
if err != nil {
fmt.Fprintf(os.Stderr, "%s\n", string(output))
return err
}
pkg, err = build.Import(llgopkgpath, "", build.FindOnly)
if err != nil {
return err
}
llgobin = path.Join(pkg.BinDir, "llgo")
// If the user did not specify -triple on the command
// line, ask llgo for it now.
if triple == "" {
output, err = exec.Command(llgobin, "-print-triple").CombinedOutput()
if err != nil {
fmt.Fprintf(os.Stderr, "%s\n", string(output))
return err
}
triple = strings.TrimSpace(string(output))
}
if err = initGOVARS(triple); err != nil {
return err
}
log.Printf("GOARCH = %s, GOOS = %s", GOARCH, GOOS)
log.Printf("Built %s", llgobin)
return nil
}
开发者ID:kelsieflynn,项目名称:llgo,代码行数:58,代码来源:buildllgo.go
示例9: init
func init() {
var err error
govdep1, err = build.Import("github.com/brianm/govdep1", ".", 0)
if err != nil {
panic(err)
}
govdep2, err = build.Import("bitbucket.org/xnio/govdep2", ".", 0)
if err != nil {
panic(err)
}
}
开发者ID:CadeLaRen,项目名称:gov,代码行数:12,代码来源:git_test.go
示例10: newapp
func newapp(args []string) {
if len(args) == 0 {
eprintf(newShortDesc)
}
filepath.Join(peony.GetPeonyPath(), "templates")
importPath := args[0]
gopath := build.Default.GOPATH
if gopath == "" {
eprintf("please set the GOPATH\n", importPath)
}
if filepath.IsAbs(importPath) {
eprintf("importpath[%s] looks like the file path.\n", importPath)
}
if _, err := build.Import(importPath, "", build.FindOnly); err == nil {
eprintf("importpath[%s] already exist.\n", importPath)
}
if _, err := build.Import(peony.PEONY_IMPORTPATH, "", build.FindOnly); err != nil {
eprintf("peony source is required.\n")
}
tmplatesPath := filepath.Join(peony.GetPeonyPath(), "templates")
errorsPath := filepath.Join(peony.GetPeonyPath(), "views", "errors")
srcPath := filepath.Join(filepath.SplitList(gopath)[0], "src")
appPath := filepath.Join(srcPath, filepath.FromSlash(importPath))
if err := os.Mkdir(appPath, 0777); err != nil {
eprintf("mdir app dir error, %s\n", err.Error())
}
if err := copyDir(tmplatesPath, appPath); err != nil {
eprintf("copy dir error, %s\n", err.Error())
}
if err := copyDir(errorsPath, filepath.Join(appPath, "app", "views", "errors")); err != nil {
eprintf("copy dir error, %s\n", err.Error())
}
appName := filepath.Base(filepath.FromSlash(importPath))
param := map[string]string{
"AppName": appName,
"ImportPath": importPath,
"SecKey": peony.GenSecKey(),
}
if err := genConfig(appPath, param); err != nil {
eprintf("generator configure error, %s\n", err.Error())
}
fmt.Println("app already is ready, please execute command: peony run", importPath)
}
开发者ID:Joinhack,项目名称:peony,代码行数:50,代码来源:new.go
示例11: Init
func Init(importPath string, mode string) {
RunMode = mode
// Find the user's app path.
importPath = strings.TrimRight(importPath, "/")
pkg, err := build.Import(importPath, "", build.FindOnly)
if err != nil {
log.Fatalln("Failed to import", importPath, "with error:", err)
}
BasePath = pkg.Dir
if BasePath == "" {
log.Fatalf("Failed to find code. Did you pass the import path?")
}
AppName = filepath.Base(BasePath)
AppPath = path.Join(BasePath, "app")
ViewsPath = path.Join(AppPath, "views")
ImportPath = importPath
// Find the provided resources.
revelPkg, err := build.Import("github.com/robfig/revel", "", build.FindOnly)
if err != nil {
log.Fatalf("Failed to find revel code.")
}
RevelPath = revelPkg.Dir
RevelTemplatePath = path.Join(RevelPath, "templates")
// Load application.conf
Config, err = LoadConfig(path.Join(BasePath, "conf", "app.conf"))
if err != nil {
log.Fatalln("Failed to load app.conf:", err)
}
Config.SetSection(mode)
secretStr, err := Config.String("app.secret")
if err != nil {
log.Fatalln("No app.secret provided.")
}
secretKey = []byte(secretStr)
// Configure logging.
TRACE = getLogger("trace")
INFO = getLogger("info")
WARN = getLogger("warn")
ERROR = getLogger("error")
for _, hook := range InitHooks {
hook()
}
revelInit = true
}
开发者ID:rjmcguire,项目名称:revel,代码行数:50,代码来源:revel.go
示例12: newApp
func newApp(args []string) {
if len(args) == 0 {
errorf("No import path given.\nRun 'revel help new' for usage.\n")
}
gopath := build.Default.GOPATH
if gopath == "" {
errorf("Abort: GOPATH environment variable is not set. " +
"Please refer to http://golang.org/doc/code.html to configure your Go environment.")
}
importPath := args[0]
if path.IsAbs(importPath) {
errorf("Abort: '%s' looks like a directory. Please provide a Go import path instead.",
importPath)
}
_, err := build.Import(importPath, "", build.FindOnly)
if err == nil {
fmt.Fprintf(os.Stderr, "Abort: Import path %s already exists.\n", importPath)
return
}
revelPkg, err := build.Import(revel.REVEL_IMPORT_PATH, "", build.FindOnly)
if err != nil {
fmt.Fprintf(os.Stderr, "Abort: Could not find Revel source code: %s\n", err)
return
}
srcRoot := path.Join(filepath.SplitList(gopath)[0], "src")
appDir := path.Join(srcRoot, filepath.FromSlash(importPath))
err = os.MkdirAll(appDir, 0777)
panicOnError(err, "Failed to create directory "+appDir)
skeletonBase = path.Join(revelPkg.Dir, "skeleton")
mustCopyDir(appDir, skeletonBase, map[string]interface{}{
// app.conf
"AppName": filepath.Base(appDir),
"Secret": genSecret(),
})
// Dotfiles are skipped by mustCopyDir, so we have to explicitly copy the .gitignore.
gitignore := ".gitignore"
mustCopyFile(path.Join(appDir, gitignore), path.Join(skeletonBase, gitignore))
fmt.Fprintln(os.Stdout, "Your application is ready:\n ", appDir)
fmt.Fprintln(os.Stdout, "\nYou can run it with:\n revel run", importPath)
}
开发者ID:ubik86,项目名称:revel,代码行数:48,代码来源:new.go
示例13: doParseReflect
func doParseReflect() {
buildpkg, err := build.Import("reflect", "", 0)
if err != nil {
parseReflectResult, parseReflectError = nil, err
return
}
filenames := make([]string, len(buildpkg.GoFiles))
for i, f := range buildpkg.GoFiles {
filenames[i] = path.Join(buildpkg.Dir, f)
}
fset := token.NewFileSet()
files, err := parseFiles(fset, filenames)
if err != nil {
parseReflectResult, parseReflectError = nil, err
return
}
pkg, err := ast.NewPackage(fset, files, types.GcImport, types.Universe)
if err != nil {
parseReflectResult, parseReflectError = nil, err
return
}
_, err = types.Check(fset, pkg)
if err != nil {
parseReflectResult, parseReflectError = nil, err
return
}
parseReflectResult, parseReflectError = pkg, nil
return
}
开发者ID:spate,项目名称:llgo,代码行数:33,代码来源:reflect.go
示例14: scanDirectory
func scanDirectory(path, srcDir string) (ret []string, err error) {
pkg, err := build.Import(path, srcDir, build.AllowBinary)
if err != nil {
return ret, err
}
for _, imp := range pkg.Imports {
switch {
case isStandardImport(imp):
// Ignore standard packages
case !build.IsLocalImport(imp):
// Add the external package
ret = appendPkg(ret, imp)
fallthrough
default:
// Does the recursive walk
pkgs, err := scanDirectory(imp, pkg.Dir)
if err != nil {
return ret, err
}
ret = appendPkgs(ret, pkgs)
}
}
return ret, err
}
开发者ID:wingdog,项目名称:gom,代码行数:26,代码来源:gen.go
示例15: restore
// restore checks out the given revision.
func restore(dep Dependency) error {
rev, ok := restored[dep.root]
debugln(rev)
debugln(ok)
debugln(dep.root)
if ok {
if rev != dep.Rev {
return errors.New("Wanted to restore rev " + dep.Rev + ", already restored rev " + rev + " for another package in the repo")
}
verboseln("Skipping already restored repo")
return nil
}
debugln("Restoring:", dep.ImportPath, dep.Rev)
pkg, err := build.Import(dep.ImportPath, ".", build.FindOnly)
if err != nil {
// This should never happen
debugln("Error finding package "+dep.ImportPath+" on restore:", err)
return err
}
err = dep.vcs.RevSync(pkg.Dir, dep.Rev)
if err == nil {
restored[dep.root] = dep.Rev
}
return err
}
开发者ID:mitake,项目名称:godep,代码行数:27,代码来源:restore.go
示例16: NewSubService
func NewSubService(log skynet.Logger, servicePath, args, uuid string) (ss *SubService, err error) {
ss = &SubService{
ServicePath: servicePath,
Args: args,
// TODO: proper argument splitting
}
ss.argv, err = shellquote.Split(args)
if err != nil {
return
}
ss.argv = append([]string{"-uuid", uuid}, ss.argv...)
//verify that it exists on the local system
pkg, err := build.Import(ss.ServicePath, "", 0)
if err != nil {
return
}
if pkg.Name != "main" {
return
}
_, binName := path.Split(ss.ServicePath)
binPath := filepath.Join(pkg.BinDir, binName)
ss.binPath = binPath
return
}
开发者ID:sdmajor,项目名称:skynet,代码行数:30,代码来源:subservice.go
示例17: defaultPaths
func defaultPaths() string {
pkg, err := build.Import(testPkg, "", build.FindOnly)
if err != nil {
return ""
}
return pkg.Dir
}
开发者ID:dsnet,项目名称:compress,代码行数:7,代码来源:main.go
示例18: main
func main() {
flag.Parse()
if build.Default.GOARCH == "amd64" {
ptrKind = "Q"
ptrSize = 8
if *useInt64 {
intSize = 8
newIntSize = intSize
intKind = "Q"
}
if *fixInt64 {
newIntSize = 8
*fixOffset = true
}
}
args := flag.Args()
if len(args) == 0 {
p, err := build.ImportDir(".", 0)
if err != nil {
log.Fatal(err)
}
check(p)
} else {
for _, arg := range args {
p, err := build.Import(arg, "", 0)
if err != nil {
log.Print(err)
continue
}
check(p)
}
}
}
开发者ID:0x7cc,项目名称:rsc,代码行数:33,代码来源:main.go
示例19: init
func init() {
var err error
example, err = build.Import("github.com/brianm/gov/example", ".", 0)
if err != nil {
panic(err)
}
}
开发者ID:CadeLaRen,项目名称:gov,代码行数:7,代码来源:plan_test.go
示例20: init
func init() {
unchecked = make(map[marker]bool)
blank = make(map[marker]bool)
pkg, err := build.Import(testPackage, "", 0)
if err != nil {
panic("failed to import test package")
}
fset := token.NewFileSet()
astPkg, err := parser.ParseDir(fset, pkg.Dir, nil, parser.ParseComments)
if err != nil {
panic("failed to parse test package")
}
for _, file := range astPkg["main"].Files {
for _, comment := range file.Comments {
text := comment.Text()
pos := fset.Position(comment.Pos())
switch text {
case "UNCHECKED\n":
unchecked[marker{pos.Filename, pos.Line}] = true
case "BLANK\n":
blank[marker{pos.Filename, pos.Line}] = true
}
}
}
}
开发者ID:robfig,项目名称:errcheck,代码行数:27,代码来源:errcheck_test.go
注:本文中的go/build.Import函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论