當前位置: 首頁>>代碼示例>>Golang>>正文


Golang loggers.Error函數代碼示例

本文整理匯總了Golang中github.com/mijia/gobuildweb/loggers.Error函數的典型用法代碼示例。如果您正苦於以下問題:Golang Error函數的具體用法?Golang Error怎麽用?Golang Error使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了Error函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: startRunner

func (app *AppShell) startRunner() {
	for task := range app.taskChan {
		switch task.taskType {
		case kTaskBuildImages:
			app.curError = app.buildImages(task.module)
		case kTaskBuildStyles:
			app.curError = app.buildStyles(task.module)
		case kTaskBuildJavaScripts:
			app.curError = app.buildJavaScripts(task.module)
		case kTaskGenAssetsMapping:
			app.curError = app.genAssetsMapping()
		case kTaskBinaryTest:
			app.curError = app.binaryTest(task.module)
		case kTaskBuildBinary:
			app.curError = app.buildBinary()
		case kTaskBinaryRestart:
			if app.curError == nil {
				if err := app.kill(); err != nil {
					loggers.Error("App cannot be killed, maybe you should restart the gobuildweb: %v", err)
				} else {
					if err := app.start(); err != nil {
						loggers.Error("App cannot be started, maybe you should restart the gobuildweb: %v", err)
					}
				}
			} else {
				loggers.Warn("You have errors with current assets and binary, please fix that ...")
			}
			fmt.Println()
			loggers.Info("Waiting for the file changes ...")
		}
	}
}
開發者ID:yihe2,項目名稱:gobuildweb,代碼行數:32,代碼來源:app.go

示例2: updateConfig

func (pw *ProjectWatcher) updateConfig() {
	loggers.Info("Reloading the project.toml file ...")
	var newConfig ProjectConfig
	if _, err := toml.DecodeFile("project.toml", &newConfig); err != nil {
		loggers.Error("We found the project.toml has changed, but it contains some error, will omit it.")
		loggers.Error("TOML Error: %v", err)
		fmt.Println()
		loggers.Info("Waiting for the file changes ...")
	} else {
		loggers.Succ("Loaded the new project.toml, will update all the dependencies ...")
		rootConfig.Lock()
		rootConfig.Package = newConfig.Package
		rootConfig.Assets = newConfig.Assets
		rootConfig.Distribution = newConfig.Distribution
		rootConfig.Unlock()
		if err := updateGolangDeps(); err != nil {
			loggers.Error("Failed to load project Go dependencies, %v", err)
			return
		}
		if err := updateAssetsDeps(); err != nil {
			loggers.Error("Failed to load project assets dependencies, %v", err)
			return
		}
		pw.addTask(kTaskBuildImages, "")
		pw.addTask(kTaskBuildStyles, "")
		pw.addTask(kTaskBuildJavaScripts, "")
		pw.addTask(kTaskGenAssetsMapping, "")
		pw.addTask(kTaskBuildBinary, "")
		pw.addTask(kTaskBinaryRestart, "")
	}
}
開發者ID:changshaopeng,項目名稱:gobuildweb,代碼行數:31,代碼來源:cmds.go

示例3: commandDist

func commandDist(args []string) error {
	if err := updateGolangDeps(); err != nil {
		loggers.Error("Failed to load project #Golang dependencies, %v", err)
		return err
	}
	if err := updateAssetsDeps(); err != nil {
		loggers.Error("Failed to load project assets dependencies, %v", err)
		return err
	}

	return NewAppShell(args).Dist()
}
開發者ID:changshaopeng,項目名稱:gobuildweb,代碼行數:12,代碼來源:cmds.go

示例4: getJsonAssetsMapping

func (a _Asset) getJsonAssetsMapping() map[string]string {
	mapping := make(map[string]string)
	filename := a.config.AssetsMappingJson
	data, err := ioutil.ReadFile(filename)
	if err != nil {
		loggers.Error(fmt.Sprintf("Cannot decoding the assets into json, %v", err))
	} else {
		err = json.Unmarshal(data, &mapping)
		if err != nil {
			loggers.Error(fmt.Sprintf("Cannot unmarshal the assets into json, %v", err))
		}
	}
	return mapping
}
開發者ID:changshaopeng,項目名稱:gobuildweb,代碼行數:14,代碼來源:asset.go

示例5: Dump

func (d _GoPkgMappingDumper) Dump(mapping *AssetsMapping) error {
	pkgName, targetPath := d.GetPkgPath()

	mapping.PkgName = pkgName
	sort.Sort(mapping)

	if file, err := os.Create(targetPath); err != nil {
		return fmt.Errorf("Cannot create the assets mapping go file, %+v", err)
	} else {
		defer file.Close()
		if err := tmAssetsMapping.Execute(file, mapping); err != nil {
			return fmt.Errorf("Cannot generate assets mapping file, %+v", err)
		}
	}

	var out bytes.Buffer
	cmd := exec.Command("gofmt", "-w", targetPath)
	cmd.Stderr = &out
	if err := cmd.Run(); err != nil {
		loggers.Error("[AssetMapping] failed to gofmt source code, %v", out.String())
		return err
	}
	loggers.Succ("[AssetMappings] Saved asssets mapping go file: %q", targetPath)
	return nil
}
開發者ID:changshaopeng,項目名稱:gobuildweb,代碼行數:25,代碼來源:mappings.go

示例6: updateGolangDeps

func updateGolangDeps() error {
	rootConfig.RLock()
	defer rootConfig.RUnlock()

	if rootConfig.Package == nil || len(rootConfig.Package.Dependencies) == 0 {
		return nil
	}

	fmt.Println()
	loggers.Info("Start to loading Go dependencies...")
	if hasGetColangDeps() {
		loggers.Info("Has Loaded Go package dependencies")
		return nil
	}
	params := []string{"get", ""}
	for _, dep := range rootConfig.Package.Dependencies {
		params[len(params)-1] = dep
		loggers.Info("Loading Go package dependency: %v", dep)
		getCmd := exec.Command("go", params...)
		getCmd.Stdout = os.Stdout
		getCmd.Stderr = os.Stderr
		getCmd.Env = mergeEnv(nil)
		if err := getCmd.Run(); err != nil {
			loggers.Error("Error when run go get: go %v, %v", params, err)
			return err
		}
	}
	loggers.Succ("Loaded Go package dependencies: \n\t%v",
		strings.Join(rootConfig.Package.Dependencies, "\n\t"))
	return nil
}
開發者ID:changshaopeng,項目名稱:gobuildweb,代碼行數:31,代碼來源:cmds.go

示例7: commandRun

func commandRun(args []string) error {
	if err := updateGolangDeps(); err != nil {
		loggers.Error("Failed to load project Go dependencies, %v", err)
		return err
	}
	if err := updateAssetsDeps(); err != nil {
		loggers.Error("Failed to load project assets dependencies, %v", err)
		return err
	}

	fmt.Println()
	if err := NewProjectWatcher().runAndWatch(".", args); err != nil {
		loggers.Error("Failed to start watching project changes, %v", err)
		return err
	}
	return nil
}
開發者ID:changshaopeng,項目名稱:gobuildweb,代碼行數:17,代碼來源:cmds.go

示例8: Dist

func (app *AppShell) Dist() error {
	app.isProduction = true
	fmt.Println()
	loggers.Info("Creating distribution package for %v-%v",
		rootConfig.Package.Name, rootConfig.Package.Version)

	var err error
	if err = app.buildImages(""); err != nil {
		loggers.Error("Error when building images, %v", err)
	} else if err = app.genAssetsMapping(); err != nil {
		loggers.Error("Error when generating assets mapping source code, %v", err)
	} else if err = app.buildStyles(""); err != nil {
		loggers.Error("Error when building stylesheets, %v", err)
	} else if err = app.clearJavaScriptsAssets(); err != nil {
		loggers.Error("Error when clear javascripts, %v", err)
	} else if err = app.buildJavaScripts(APP_SHELL_JS_TASK_INIT_ENTRY_KEY); err != nil {
		loggers.Error("Error when building javascripts, %v", err)
	} else if err = app.genAssetsMapping(); err != nil {
		loggers.Error("Error when generating assets mapping source code, %v", err)
	} else if err = app.binaryTest(""); err != nil {
		loggers.Error("You have failed test cases, %v", err)
	} else if err = app.distExtraCommand(); err != nil {
		loggers.Error("Error when running the distribution extra command, %v", err)
	} else if err == nil {
		goOs, goArch := runtime.GOOS, runtime.GOARCH
		targets := append(rootConfig.Distribution.CrossTargets, [2]string{goOs, goArch})
		visited := make(map[string]struct{})
		for _, target := range targets {
			buildTarget := fmt.Sprintf("%s_%s", target[0], target[1])
			if _, ok := visited[buildTarget]; ok {
				continue
			}
			visited[buildTarget] = struct{}{}
			if err = app.buildBinary(target[:]...); err != nil {
				loggers.Error("Error when building binary for %v, %v", target, err)
			}
		}
	}
	if err == nil {
		err = app.buildPackage()
	}
	return err
}
開發者ID:changshaopeng,項目名稱:gobuildweb,代碼行數:43,代碼來源:app.go

示例9: maybeGoCodeChanged

func (pw *ProjectWatcher) maybeGoCodeChanged(fname string) {
	if strings.HasSuffix(fname, ".go") {
		goModule := path.Dir(fname)
		if pw.hasGoTests(goModule) {
			if moduleName, err := pw.goModuleName(goModule); err == nil {
				pw.addTask(kTaskBinaryTest, moduleName)
			} else {
				loggers.Error("Cannot get go module path name, %v", err)
			}
		}
		pw.addTask(kTaskBuildBinary, goModule)
		pw.addTask(kTaskBinaryRestart, "")
	}
}
開發者ID:changshaopeng,項目名稱:gobuildweb,代碼行數:14,代碼來源:cmds.go

示例10: Build

func (css _StyleSheet) Build(isProduction bool) error {
	filename := fmt.Sprintf("assets/stylesheets/%s.styl", css.entry)
	isStylus := true
	if exist, _ := css.checkFile(filename, true); !exist {
		filename = fmt.Sprintf("assets/stylesheets/%s.css", css.entry)
		if exist, err := css.checkFile(filename, true); !exist {
			return err
		} else {
			isStylus = false
		}
	}

	target := fmt.Sprintf("public/stylesheets/%s.css", css.entry)

	// * Maybe it's a template using images, styles assets links
	// TODO

	// * Maybe we need to call stylus preprocess
	if isStylus {
		params := []string{"--use", "nib", filename, "--out", "public/stylesheets"}
		if isProduction {
			params = append(params, "--compress")
		} else {
			params = append(params, "--sourcemap-inline")
		}
		params = append(params, "--include-css")
		// add asset plugin to change original file path to the finger printed one
		if css.config.AssetsMappingJson != "" {
			params = append(params, "--use", getStylusPluginPath())
		}
		cmd := exec.Command("./node_modules/stylus/bin/stylus", params...)
		loggers.Debug("[CSS][%s] Building asset: %s, %v", css.entry, filename, cmd.Args)
		cmd.Stderr = os.Stderr
		cmd.Stdout = os.Stdout
		cmd.Env = css.getEnv(isProduction)
		if err := cmd.Run(); err != nil {
			loggers.Error("[CSS][%s] Error when building asset %v, %v", css.entry, cmd.Args, err)
			return err
		}
	} else {
		if err := css.copyFile(target, filename); err != nil {
			return err
		}
	}
	// * generate the hash, clear old bundle, move to target
	target = css.addFingerPrint("public/stylesheets", css.entry+".css")
	loggers.Succ("[CSS][%s] Saved assset: %s", css.entry, target)

	return nil
}
開發者ID:JeekyYang,項目名稱:gobuildweb,代碼行數:50,代碼來源:css.go

示例11: distExtraCommand

func (app *AppShell) distExtraCommand() error {
	extraCmd := rootConfig.Distribution.ExtraCmd
	if extraCmd == nil || len(extraCmd) == 0 {
		return nil
	}
	cmd := exec.Command(extraCmd[0], extraCmd[1:]...)
	cmd.Stderr = os.Stderr
	cmd.Stdout = os.Stdout
	if err := cmd.Run(); err != nil {
		loggers.Error("Error when running distribution extra command, %v, %s", extraCmd, err)
		return err
	}
	loggers.Succ("Run extra command succ: %v", cmd.Args)
	return nil
}
開發者ID:yihe2,項目名稱:gobuildweb,代碼行數:15,代碼來源:app.go

示例12: hasGetColangDeps

//是否已經下載了go運行所需要的包,是否可以編譯成功
func hasGetColangDeps() bool {
	cmd := exec.Command("go", "build")
	loggers.Info("Started to go build...")
	err := cmd.Start()
	if err != nil {
		loggers.Error("Failed to go build... %+v", err)
		return false
	}
	done := make(chan error, 1)
	go func() {
		done <- cmd.Wait()
	}()
	err = <-done
	if err != nil {
		loggers.Error("Failed to go build...%+v", err)
	} else {
		loggers.Info("Successed to go build...")
		cmd := exec.Command("rm", "zhiwang_web")
		cmd.Run()
		return true
	}

	return false
}
開發者ID:changshaopeng,項目名稱:gobuildweb,代碼行數:25,代碼來源:cmds.go

示例13: binaryTest

func (app *AppShell) binaryTest(module string) error {
	return nil // close the test first, will reconsider this
	if module == "" {
		module = "./..."
	}
	testCmd := exec.Command("go", "test", "-v", module)
	testCmd.Stderr = os.Stderr
	testCmd.Stdout = os.Stdout
	testCmd.Env = mergeEnv(nil)
	if err := testCmd.Run(); err != nil {
		loggers.Error("Error when testing go modules[%s], %v", module, err)
		return err
	}
	loggers.Succ("Module[%s] Test passed: %v", module, testCmd.Args)
	return nil
}
開發者ID:yihe2,項目名稱:gobuildweb,代碼行數:16,代碼來源:app.go

示例14: buildBinary

func (app *AppShell) buildBinary(params ...string) error {
	goOs, goArch := runtime.GOOS, runtime.GOARCH
	if len(params) == 2 && (goOs != params[0] || goArch != params[1]) {
		goOs, goArch = params[0], params[1]
	}

	rootConfig.RLock()
	builder := rootConfig.Package.Builder
	binName := app.binaryName(rootConfig.Package.Name, rootConfig.Package.Version, goOs, goArch)
	var buildOpts []string
	if app.isProduction {
		buildOpts = make([]string, len(rootConfig.Distribution.BuildOpts))
		copy(buildOpts, rootConfig.Distribution.BuildOpts)
	} else {
		buildOpts = make([]string, len(rootConfig.Package.BuildOpts))
		copy(buildOpts, rootConfig.Package.BuildOpts)
	}
	rootConfig.RUnlock()

	cmdName := "go"
	flags := make([]string, 0, 3+len(buildOpts))
	if builder != "" {
		flags = append(flags, "go")
		cmdName = builder
	}
	flags = append(flags, "build")
	flags = append(flags, buildOpts...)
	flags = append(flags, []string{"-o", binName}...)
	buildCmd := exec.Command(cmdName, flags...)
	buildCmd.Stderr = os.Stderr
	buildCmd.Stdout = os.Stdout
	buildCmd.Env = mergeEnv(map[string]string{
		"GOOS":   goOs,
		"GOARCH": goArch,
	})
	loggers.Debug("Running build: %v", buildCmd.Args)
	start := time.Now()
	if err := buildCmd.Run(); err != nil {
		loggers.Error("Building failed")
		return err
	}
	app.binName = binName
	duration := float64(time.Since(start).Nanoseconds()) / 1e6
	loggers.Succ("Got binary built %s, takes=%.3fms", binName, duration)
	return nil
}
開發者ID:JeekyYang,項目名稱:gobuildweb,代碼行數:46,代碼來源:app.go

示例15: updateAssetsDeps

func updateAssetsDeps() error {
	rootConfig.RLock()
	defer rootConfig.RUnlock()

	if rootConfig.Assets == nil || len(rootConfig.Assets.Dependencies) == 0 {
		return nil
	}

	fmt.Println()
	loggers.Info("Start to loading assets dependencies...")
	checkParams := []string{"list", "--depth", "0", ""}
	params := []string{"install", ""}
	deps := make([]string, len(rootConfig.Assets.Dependencies), len(rootConfig.Assets.Dependencies)+1)
	copy(deps, rootConfig.Assets.Dependencies)
	// add all dev deps for xxxify
	deps = append(deps, "browserify", "coffeeify", "envify", "uglifyify", "babelify", "babel-preset-es2015", "babel-preset-react", "nib", "stylus")
	for _, dep := range deps {
		checkParams[len(checkParams)-1] = dep
		listCmd := exec.Command("npm", checkParams...)
		listCmd.Env = mergeEnv(nil)
		if err := listCmd.Run(); err == nil {
			// the module has been installed
			loggers.Info("Checked npm module: %v", dep)
			continue
		}

		params[len(params)-1] = dep
		loggers.Info("Loading npm module: %v", dep)
		installCmd := exec.Command("npm", params...)
		installCmd.Stdout = os.Stdout
		installCmd.Stderr = os.Stderr
		installCmd.Env = mergeEnv(nil)
		if err := installCmd.Run(); err != nil {
			loggers.Error("Error when run npm install: npm %v, %v", params, err)
			return err
		}
	}
	loggers.Succ("Loaded assets dependencies: \n\t%v", strings.Join(deps, "\n\t"))
	return nil
}
開發者ID:changshaopeng,項目名稱:gobuildweb,代碼行數:40,代碼來源:cmds.go


注:本文中的github.com/mijia/gobuildweb/loggers.Error函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。