本文整理汇总了Golang中github.com/gpmgo/gopm/log.Fatal函数的典型用法代码示例。如果您正苦于以下问题:Golang Fatal函数的具体用法?Golang Fatal怎么用?Golang Fatal使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Fatal函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: 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])
}
}
示例2: 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")
}
}
}
示例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!")
}
示例4: 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))
}
示例5: 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
}
示例6: 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
}
示例7: 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
}
示例8: 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
}
示例9: 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
}
示例10: 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!")
}
示例11: 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!")
}
示例12: 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())
}
}
示例13: 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
}
示例14: 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
}
示例15: 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
}