本文整理汇总了Golang中github.com/gpmgo/gopm/log.Error函数的典型用法代码示例。如果您正苦于以下问题:Golang Error函数的具体用法?Golang Error怎么用?Golang Error使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Error函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: downloadPackage
// downloadPackage downloads package either use version control tools or not.
func downloadPackage(ctx *cli.Context, nod *doc.Node) (*doc.Node, []string) {
log.Message("Downloading", fmt.Sprintf("package: %[email protected]%s:%s",
nod.ImportPath, nod.Type, doc.CheckNodeValue(nod.Value)))
// Mark as donwloaded.
downloadCache[nod.RootPath] = true
// Check if only need to use VCS tools.
var imports []string
var err error
gopathDir := path.Join(installGopath, nod.RootPath)
vcs := getVcsName(gopathDir)
if ctx.Bool("update") && ctx.Bool("gopath") && len(vcs) > 0 {
err = updateByVcs(vcs, gopathDir)
imports = doc.GetAllImports([]string{gopathDir}, nod.RootPath, false)
} else {
// If package has revision and exist, then just check dependencies.
if nod.IsGetDepsOnly {
return nod, doc.GetAllImports([]string{path.Join(installRepoPath, nod.RootPath) + versionSuffix(nod.Value)},
nod.RootPath, ctx.Bool("example"))
}
nod.Revision = doc.LocalNodes.MustValue(nod.RootPath, "value")
imports, err = doc.PureDownload(nod, installRepoPath, ctx) //CmdGet.Flags)
}
if err != nil {
log.Error("get", "Fail to download pakage: "+nod.ImportPath)
log.Error("", "\t"+err.Error())
failConut++
os.RemoveAll(installRepoPath + "/" + nod.RootPath)
return nil, nil
}
return nod, imports
}
开发者ID:josephyzhou,项目名称:gopm,代码行数:34,代码来源:get.go
示例2: init
func init() {
hd, err := com.HomeDir()
if err != nil {
log.Error("", "Fail to get current user")
log.Fatal("", err.Error())
}
HomeDir = strings.Replace(RawHomeDir, "~", hd, -1)
cfgPath := path.Join(HomeDir, GOPM_CONFIG_FILE)
if !com.IsExist(cfgPath) {
os.MkdirAll(path.Dir(cfgPath), os.ModePerm)
if _, err = os.Create(cfgPath); err != nil {
log.Error("", "Fail to create gopm config file")
log.Fatal("", err.Error())
}
}
Cfg, err = goconfig.LoadConfigFile(cfgPath)
if err != nil {
log.Error("", "Fail to load gopm config file")
log.Fatal("", err.Error())
}
LoadLocalNodes()
LoadPkgNameList(path.Join(HomeDir, PKG_NAME_LIST_PATH))
}
开发者ID:kulasama,项目名称:gopm,代码行数:26,代码来源:conf.go
示例3: runGen
// scan a directory and gen a gopm file
func runGen(ctx *cli.Context) {
setup(ctx)
if !com.IsExist(".gopmfile") {
os.Create(".gopmfile")
}
gf, err := goconfig.LoadConfigFile(".gopmfile")
if err != nil {
log.Error("gen", "Cannot load gopmfile:")
log.Fatal("", "\t"+err.Error())
}
// Get dependencies.
imports := doc.GetAllImports([]string{workDir},
parseTarget(gf.MustValue("target", "path")), ctx.Bool("example"))
for _, p := range imports {
p = doc.GetProjectPath(p)
if strings.HasSuffix(workDir, p) {
continue
}
if value := gf.MustValue("deps", p); len(value) == 0 {
gf.SetValue("deps", p, "")
}
}
err = goconfig.SaveConfigFile(gf, ".gopmfile")
if err != nil {
log.Error("gen", "Fail to save gopmfile:")
log.Fatal("", "\t"+err.Error())
}
log.Success("SUCC", "gen", "Generate gopmfile successfully!")
}
开发者ID:nashtsai,项目名称:gopm,代码行数:36,代码来源:gen.go
示例4: validPath
// validPath checks if the information of the package is valid.
func validPath(info string) (string, string) {
infos := strings.Split(info, ":")
l := len(infos)
switch {
case l == 1:
// for local imports
if com.IsFile(infos[0]) {
return doc.LOCAL, infos[0]
}
return doc.BRANCH, ""
case l == 2:
switch infos[1] {
case doc.TRUNK, doc.MASTER, doc.DEFAULT:
infos[1] = ""
}
return infos[0], infos[1]
default:
log.Error("", "Cannot parse dependency version:")
log.Error("", "\t"+info)
log.Help("Try 'gopm help get' to get more information")
return "", ""
}
}
开发者ID:nashtsai,项目名称:gopm,代码行数:26,代码来源:cmd.go
示例5: SaveLocalNodes
func SaveLocalNodes() {
if err := goconfig.SaveConfigFile(LocalNodes,
path.Join(HomeDir+LocalNodesFile)); err != nil {
log.Error("", "Fail to save localnodes.list:")
log.Error("", "\t"+err.Error())
}
}
开发者ID:kulasama,项目名称:gopm,代码行数:7,代码来源:conf.go
示例6: LoadPkgNameList
func LoadPkgNameList(filePath string) {
PackageNameList = make(map[string]string)
// If file does not exist, simply ignore.
if !com.IsFile(filePath) {
return
}
data, err := ioutil.ReadFile(filePath)
if err != nil {
log.Error("Package name list", "Fail to read file")
log.Fatal("", err.Error())
}
pkgs := strings.Split(string(data), "\n")
for i, line := range pkgs {
infos := strings.Split(line, "=")
if len(infos) != 2 {
// Last item might be empty line.
if i == len(pkgs)-1 {
continue
}
log.Error("", "Fail to parse package name: "+line)
log.Fatal("", "Invalid package name information")
}
PackageNameList[strings.TrimSpace(infos[0])] =
strings.TrimSpace(infos[1])
}
}
开发者ID:kulasama,项目名称:gopm,代码行数:29,代码来源:conf.go
示例7: buildBinary
func buildBinary(ctx *cli.Context, args ...string) {
genNewGoPath(ctx, false)
log.Trace("Building...")
cmdArgs := []string{"go", "build"}
cmdArgs = append(cmdArgs, args...)
err := execCmd(newGoPath, newCurPath, cmdArgs...)
if err != nil {
log.Error("build", "fail to build program:")
log.Fatal("", "\t"+err.Error())
}
if isWindowsXP {
fName := path.Base(pkgName)
binName := fName + ".exe"
os.Remove(binName)
exePath := filepath.Join(curPath, doc.VENDOR, "src", pkgName, binName)
if com.IsFile(exePath) {
err = os.Rename(exePath, filepath.Join(curPath, binName))
if err != nil {
log.Error("build", "fail to move binary:")
log.Fatal("", "\t"+err.Error())
}
} else {
log.Warn("No binary generated")
}
}
}
开发者ID:jexwn,项目名称:gopm,代码行数:29,代码来源:build.go
示例8: GetPkgFullPath
func GetPkgFullPath(short string) string {
name, ok := PackageNameList[short]
if !ok {
log.Error("", "Invalid package name")
log.Error("", "It's not a invalid import path and no match in the package name list:")
log.Fatal("", "\t"+short)
}
return name
}
开发者ID:kulasama,项目名称:gopm,代码行数:9,代码来源:conf.go
示例9: execCmd
func execCmd(gopath, curPath string, args ...string) error {
cwd, err := os.Getwd()
if err != nil {
log.Error("", "Fail to get work directory:")
log.Fatal("", "\t"+err.Error())
}
log.Log("Changing work directory to %s", curPath)
err = os.Chdir(curPath)
if err != nil {
log.Error("", "Fail to change work directory:")
log.Fatal("", "\t"+err.Error())
}
defer func() {
log.Log("Changing work directory back to %s", cwd)
os.Chdir(cwd)
}()
err = os.Chdir(curPath)
if err != nil {
log.Error("", "Fail to change work directory:")
log.Fatal("", "\t"+err.Error())
}
oldGoPath = os.Getenv("GOPATH")
log.Log("Setting GOPATH to %s", gopath)
sep := ":"
if runtime.GOOS == "windows" {
sep = ";"
}
err = os.Setenv("GOPATH", gopath+sep+oldGoPath)
if err != nil {
log.Error("", "Fail to setting GOPATH:")
log.Fatal("", "\t"+err.Error())
}
defer func() {
log.Log("Setting GOPATH back to %s", oldGoPath)
os.Setenv("GOPATH", oldGoPath)
}()
cmd := exec.Command(args[0], args[1:]...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
log.Log("===== application outputs start =====\n")
err = cmd.Run()
log.Log("====== application outputs end ======")
return err
}
开发者ID:kulasama,项目名称:gopm,代码行数:52,代码来源:gopath.go
示例10: exePath
func exePath() string {
file, err := exec.LookPath(os.Args[0])
if err != nil {
log.Error("Update", "Fail to execute exec.LookPath")
log.Fatal("", err.Error())
}
path, err := filepath.Abs(file)
if err != nil {
log.Error("Update", "Fail to get absolutely path")
log.Fatal("", err.Error())
}
return path
}
开发者ID:kulasama,项目名称:gopm,代码行数:13,代码来源:update.go
示例11: CheckIsExistWithVCS
// CheckIsExistWithVCS returns false if directory only has VCS folder,
// or doesn't exist.
func CheckIsExistWithVCS(path string) bool {
// Check if directory exist.
if !com.IsExist(path) {
return false
}
// Check if only has VCS folder.
dirs, err := GetDirsInfo(path)
if err != nil {
log.Error("", "Fail to get directory's information")
log.Fatal("", err.Error())
}
if len(dirs) > 1 {
return true
} else if len(dirs) == 0 {
return false
}
switch dirs[0].Name() {
case ".git", ".hg", ".svn":
return false
}
return true
}
开发者ID:kulasama,项目名称:gopm,代码行数:28,代码来源:utils.go
示例12: runRun
func runRun(ctx *cli.Context) {
setup(ctx)
// Get GOPATH.
installGopath = com.GetGOPATHs()[0]
if com.IsDir(installGopath) {
isHasGopath = true
log.Log("Indicated GOPATH: %s", installGopath)
installGopath += "/src"
}
genNewGoPath(ctx, false)
log.Trace("Running...")
cmdArgs := []string{"go", "run"}
cmdArgs = append(cmdArgs, ctx.Args()...)
err := execCmd(newGoPath, newCurPath, cmdArgs...)
if err != nil {
log.Error("run", "Fail to run program:")
log.Fatal("", "\t"+err.Error())
}
log.Success("SUCC", "run", "Command executed successfully!")
}
开发者ID:nashtsai,项目名称:gopm,代码行数:25,代码来源:run.go
示例13: GetDirsInfo
// GetDirsInfo returns os.FileInfo of all sub-directories in root path.
func GetDirsInfo(rootPath string) []os.FileInfo {
rootDir, err := os.Open(rootPath)
if err != nil {
log.Error("", "Fail to open directory")
log.Fatal("", err.Error())
}
defer rootDir.Close()
dirs, err := rootDir.Readdir(0)
if err != nil {
log.Error("", "Fail to read directory")
log.Fatal("", err.Error())
}
return dirs
}
开发者ID:nashtsai,项目名称:gopm,代码行数:17,代码来源:utils.go
示例14: GetImports
// GetImports returns package denpendencies.
func GetImports(absPath, importPath string, example bool) []string {
pkg, err := build.ImportDir(absPath, build.AllowBinary)
if err != nil {
if _, ok := err.(*build.NoGoError); !ok {
log.Error("", "Fail to get imports")
log.Fatal("", err.Error())
}
}
fis := GetDirsInfo(absPath)
absPath += "/"
dirs := make([]string, 0)
for _, fi := range fis {
if fi.IsDir() && !strings.Contains(fi.Name(), VENDOR) {
dirs = append(dirs, absPath+fi.Name())
}
}
imports := make([]string, 0, len(pkg.Imports))
for _, p := range pkg.Imports {
if !IsGoRepoPath(p) && !strings.HasPrefix(p, importPath) {
imports = append(imports, p)
}
}
if len(dirs) > 0 {
imports = append(imports, GetAllImports(dirs, importPath, example)...)
}
return imports
}
开发者ID:nashtsai,项目名称:gopm,代码行数:31,代码来源:utils.go
示例15: copyToGopath
func copyToGopath(srcPath, destPath string) {
os.RemoveAll(destPath)
err := com.CopyDir(srcPath, destPath)
if err != nil {
log.Error("download", "Fail to copy to GOPATH:")
log.Fatal("", "\t"+err.Error())
}
}
开发者ID:nashtsai,项目名称:gopm,代码行数:8,代码来源:get.go
示例16: runGen
func runGen(ctx *cli.Context) {
setup(ctx)
if !com.IsExist(".gopmfile") {
os.Create(".gopmfile")
}
gf, err := goconfig.LoadConfigFile(".gopmfile")
if err != nil {
log.Error("gen", "Cannot load gopmfile:")
log.Fatal("", "\t"+err.Error())
}
targetPath := parseTarget(gf.MustValue("target", "path"))
// Get and set dependencies.
imports := doc.GetAllImports([]string{workDir}, targetPath, ctx.Bool("example"), false)
for _, p := range imports {
p = doc.GetProjectPath(p)
// Skip subpackage(s) of current project.
if isSubpackage(p, targetPath) {
continue
}
// Check if user specified the version.
if value := gf.MustValue("deps", p); len(value) == 0 {
gf.SetValue("deps", p, "")
}
}
// Get and set resources.
res := make([]string, 0, len(commonRes))
for _, cr := range commonRes {
if com.IsExist(cr) {
res = append(res, cr)
}
}
gf.SetValue("res", "include", strings.Join(res, "|"))
err = goconfig.SaveConfigFile(gf, ".gopmfile")
if err != nil {
log.Error("gen", "Fail to save gopmfile:")
log.Fatal("", "\t"+err.Error())
}
log.Success("SUCC", "gen", "Generate gopmfile successfully!")
}
开发者ID:puma007,项目名称:gopm,代码行数:46,代码来源:gen.go
示例17: downloadPackage
// downloadPackage downloads package either use version control tools or not.
func downloadPackage(ctx *cli.Context, nod *doc.Node) (*doc.Node, []string) {
log.Message("Downloading", fmt.Sprintf("package: %[email protected]%s:%s",
nod.ImportPath, nod.Type, doc.CheckNodeValue(nod.Value)))
// Mark as donwloaded.
downloadCache[nod.RootPath] = true
nod.Revision = doc.LocalNodes.MustValue(nod.RootPath, "value")
imports, err := doc.PureDownload(nod, installRepoPath, ctx) //CmdGet.Flags)
if err != nil {
log.Error("get", "Fail to download pakage: "+nod.ImportPath)
log.Error("", "\t"+err.Error())
failConut++
os.RemoveAll(installRepoPath + "/" + nod.RootPath)
return nil, nil
}
return nod, imports
}
开发者ID:nashtsai,项目名称:gopm,代码行数:19,代码来源:get.go
示例18: NewGopmfile
// NewGopmfile loads gopmgile in given directory.
func NewGopmfile(dirPath string) *goconfig.ConfigFile {
dirPath, _ = filepath.Abs(dirPath)
gf, err := goconfig.LoadConfigFile(path.Join(dirPath, GOPM_FILE_NAME))
if err != nil {
log.Error("", "Fail to load gopmfile:")
log.Fatal("", "\t"+err.Error())
}
return gf
}
开发者ID:kulasama,项目名称:gopm,代码行数:10,代码来源:conf.go
示例19: setup
// setup initialize common environment for commands.
func setup(ctx *cli.Context) {
var err error
workDir, err = os.Getwd()
if err != nil {
log.Error("setup", "Fail to get work directory:")
log.Fatal("", "\t"+err.Error())
}
log.PureMode = ctx.GlobalBool("noterm")
log.Verbose = ctx.Bool("verbose")
}
开发者ID:josephyzhou,项目名称:gopm,代码行数:12,代码来源:cmd.go
示例20: loadLocalVerInfo
func loadLocalVerInfo() (ver version) {
verPath := path.Join(doc.HomeDir, doc.VER_PATH)
// First time run should not exist.
if !com.IsExist(verPath) {
return ver
}
f, err := os.Open(verPath)
if err != nil {
log.Error("Update", "Fail to open VERSION.json")
log.Fatal("", err.Error())
}
if err := json.NewDecoder(f).Decode(&ver); err != nil {
log.Error("Update", "Fail to decode VERSION.json")
log.Fatal("", err.Error())
}
return ver
}
开发者ID:kulasama,项目名称:gopm,代码行数:20,代码来源:update.go
注:本文中的github.com/gpmgo/gopm/log.Error函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论