• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang util.LogError函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/marmelab/gaudi/util.LogError函数的典型用法代码示例。如果您正苦于以下问题:Golang LogError函数的具体用法?Golang LogError怎么用?Golang LogError使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了LogError函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: copyRelativeFiles

func (g *Gaudi) copyRelativeFiles(filePath, destination string) bool {
	// File cannot be absolute
	if util.IsFile(filePath) && filePath[0] == '/' {
		util.LogError("File '" + filePath + "' cannot be an absolute path")
	}

	// Check if the relative file exists
	absolutePath := g.ApplicationDir + "/" + filePath
	if util.IsFile(absolutePath) {

		// Move file to the build context (and keep the same file tree)
		directories := strings.Split(filePath, "/")
		if len(directories) > 1 {
			os.MkdirAll(destination+strings.Join(directories[0:len(directories)-1], "/"), 0755)
		}

		err := util.Copy(destination+filePath, absolutePath)
		if err != nil {
			util.LogError(err)
		}

		return true
	}

	return false
}
开发者ID:hungld,项目名称:gaudi,代码行数:26,代码来源:gaudi.go


示例2: parseTemplate

func (gaudi *Gaudi) parseTemplate(sourceDir, destinationDir string, file os.FileInfo, includes map[string]string, currentContainer *container.Container) {
	emptyCmd := shouldEmptyCmdForContainer(currentContainer.Name)
	templateData := TemplateData{gaudi.All, nil, emptyCmd}
	funcMap := template.FuncMap{
		"ToUpper": strings.ToUpper,
		"ToLower": strings.ToLower,
	}

	// Create destination directory if needed
	destination := destinationDir + currentContainer.Name + "/" + file.Name()
	if file.IsDir() {
		err := os.MkdirAll(destination, 0755)
		if err != nil {
			util.LogError(err)
		}

		return
	}

	// Read the template
	filePath := sourceDir + "/" + file.Name()
	rawContent, err := ioutil.ReadFile(filePath)
	if err != nil {
		util.LogError(err)
	}
	content := string(rawContent)

	// Add includes
	for name, include := range includes {
		content = strings.Replace(content, "[[ "+name+" ]]", include, -1)
	}

	// Parse it
	// We need to change default delimiters because sometimes we have to parse values like ${{{ .Val }}} which cause an error
	tmpl, templErr := template.New(filePath).Funcs(funcMap).Delims("[[", "]]").Parse(content)
	if templErr != nil {
		util.LogError(templErr)
	}

	templateData.Container = currentContainer
	var result bytes.Buffer
	err = tmpl.Execute(&result, templateData)
	if err != nil {
		util.LogError(err)
	}

	// Create the destination file
	ioutil.WriteFile(destination, []byte(result.String()), 0644)
}
开发者ID:hungld,项目名称:gaudi,代码行数:49,代码来源:gaudi.go


示例3: Run

/**
 * Start a container as binary
 */
func Run(name, currentPath string, arguments []string, ports, environments map[string]string) {
	runFunc := reflect.ValueOf(exec.Command)
	rawArgs := []string{getDockerBinaryPath(), "run", "-v=" + currentPath + ":" + currentPath, "-w=" + currentPath}

	// Add environments
	util.Debug(environments)
	for envName, envValue := range environments {
		rawArgs = append(rawArgs, "-e="+envName+"="+envValue)
	}

	// Add ports
	for portIn, portOut := range ports {
		rawArgs = append(rawArgs, "-p="+string(portIn)+":"+string(portOut))
	}

	rawArgs = append(rawArgs, name)

	// Add user arguments
	for _, argument := range arguments {
		rawArgs = append(rawArgs, argument)
	}

	runCmd := runFunc.Call(util.BuildReflectArguments(rawArgs))[0].Interface().(*exec.Cmd)
	runCmd.Stdout = os.Stdout
	runCmd.Stdin = os.Stdin
	runCmd.Stderr = os.Stderr

	util.Debug("Run command:", runCmd.Args)

	if err := runCmd.Start(); err != nil {
		util.LogError(err)
	}
}
开发者ID:nidhisarvaiya,项目名称:gaudi,代码行数:36,代码来源:docker.go


示例4: Build

func Build(name, path string) {
	buildFunc := reflect.ValueOf(exec.Command)
	rawArgs := []string{getDockerBinaryPath(), "build"}

	if *noCache {
		rawArgs = append(rawArgs, "--no-cache")
	}

	rawArgs = append(rawArgs, "-t", name, path)

	util.Debug(rawArgs)

	buildCmd := buildFunc.Call(util.BuildReflectArguments(rawArgs))[0].Interface().(*exec.Cmd)
	buildCmd.Stdin = os.Stdin

	out, err := buildCmd.CombinedOutput()
	if err != nil {
		util.Print(string(out))
		util.LogError("Error while starting container '" + name + "'")
	}

	buildCmd.Wait()

	time.Sleep(1 * time.Second)
}
开发者ID:hungld,项目名称:gaudi,代码行数:25,代码来源:docker.go


示例5: Build

func Build(name, path string) {
	buildFunc := reflect.ValueOf(exec.Command)
	rawArgs := []string{getDockerBinaryPath(), "build"}

	if *noCache {
		rawArgs = append(rawArgs, "--no-cache")
	}

	rawArgs = append(rawArgs, "-t", name, path)

	util.Debug(rawArgs)

	buildCmd := buildFunc.Call(util.BuildReflectArguments(rawArgs))[0].Interface().(*exec.Cmd)
	buildCmd.Stderr = os.Stderr

	if !*quiet {
		buildCmd.Stdout = os.Stdout
	}

	if err := buildCmd.Run(); err != nil {
		util.LogError(err)
	}

	buildCmd.Wait()

	time.Sleep(1 * time.Second)
}
开发者ID:nidhisarvaiya,项目名称:gaudi,代码行数:27,代码来源:docker.go


示例6: Start

/**
 * Start a container as a server
 */
func Start(name, image string, links []string, ports, volumes, environments map[string]string) string {
	runFunc := reflect.ValueOf(exec.Command)
	rawArgs := []string{getDockerBinaryPath(), "run", "-d", "-i", "-t", "--privileged", "--name=" + name}

	// Add environments
	util.Debug(environments)
	for envName, envValue := range environments {
		rawArgs = append(rawArgs, "-e="+envName+"="+envValue)
	}

	// Add links
	for _, link := range links {
		rawArgs = append(rawArgs, "--link="+link+":"+link)
	}

	// Add ports
	for portIn, portOut := range ports {
		rawArgs = append(rawArgs, "-p="+string(portIn)+":"+string(portOut))
	}

	// Add volumes
	for volumeHost, volumeContainer := range volumes {
		rawArgs = append(rawArgs, "-v="+volumeHost+":"+volumeContainer)
	}

	rawArgs = append(rawArgs, image)

	// Initiate the command with several arguments
	runCmd := runFunc.Call(util.BuildReflectArguments(rawArgs))[0].Interface().(*exec.Cmd)
	util.Debug("Start command:", runCmd.Args)

	out, err := runCmd.CombinedOutput()
	if err != nil {
		util.LogError(string(out))
	}

	// Inspect container to check status code
	exitCodeBuff, _ := Inspect(name, "--format", "{{.State.ExitCode}}")
	exitCode, _ := strconv.Atoi(strings.TrimSpace(string(exitCodeBuff)))

	if exitCode != 0 {
		error, _ := Logs(name)
		util.LogError("Error while starting container '" + name + "' : " + error)
	}

	return string(out)
}
开发者ID:hungld,项目名称:gaudi,代码行数:50,代码来源:docker.go


示例7: RetrieveIp

func (c *Container) RetrieveIp() {
	inspect, err := docker.Inspect(c.Id)
	if err != nil {
		util.LogError(err)
	}

	c.retrieveInfoFromInspection(inspect)
}
开发者ID:hungld,项目名称:gaudi,代码行数:8,代码来源:container.go


示例8: Init

func (gaudi *Gaudi) Init(content string) {
	err := goyaml.Unmarshal([]byte(content), &gaudi)
	if err != nil {
		util.LogError(err)
	}

	emptyCmdForContainers = strings.Split(*emptyCmdFlag, ",")

	// Init all containers
	gaudi.Applications.AddAmbassadors()
	gaudi.All = containerCollection.Merge(gaudi.Applications, gaudi.Binaries)
	if len(gaudi.All) == 0 {
		util.LogError("No application or binary to start. Are you missing a 'applications' or 'binaries' field in your configuration ?")
	}

	hasGaudiManagedContainer := gaudi.All.Init(gaudi.ApplicationDir)

	// Apply extends
	gaudi.applyInheritance()

	// Check if docker is installed
	if !docker.HasDocker() {
		util.LogError("Docker should be installed to use Gaudi (see: https://www.docker.io/gettingstarted/).")
	}

	// Check if base image is pulled
	if hasGaudiManagedContainer && !docker.ImageExists(DEFAULT_BASE_IMAGE) {
		util.PrintGreen("Pulling base image (this may take a few minutes) ...")

		docker.Pull(DEFAULT_BASE_IMAGE_WITH_TAG)
	}

	if gaudi.useNewVersion() {
		os.RemoveAll(TEMPLATE_DIR)
	}

	// Check if templates are present
	if !util.IsDir(TEMPLATE_DIR) {
		util.PrintGreen("Retrieving templates ...")

		retrieveTemplates()
		extractTemplates()
	}

	gaudi.build()
}
开发者ID:hungld,项目名称:gaudi,代码行数:46,代码来源:gaudi.go


示例9: Remove

func Remove(name string) {
	removeCmd := exec.Command(getDockerBinaryPath(), "rm", name)
	removeErr := removeCmd.Start()
	if removeErr != nil {
		util.LogError(removeErr)
	}

	time.Sleep(1 * time.Second)
}
开发者ID:nidhisarvaiya,项目名称:gaudi,代码行数:9,代码来源:docker.go


示例10: Kill

func Kill(name string) {

	killCommand := exec.Command(getDockerBinaryPath(), "kill", name)
	killErr := killCommand.Start()
	if killErr != nil {
		util.LogError(killErr)
	}

	time.Sleep(1 * time.Second)
}
开发者ID:nidhisarvaiya,项目名称:gaudi,代码行数:10,代码来源:docker.go


示例11: Init

func (collection ContainerCollection) Init(relativePath string) bool {
	hasGaudiManagedContainer := false

	// Fill name & dependencies
	for name, currentContainer := range collection {
		currentContainer.Name = name
		currentContainer.Init()

		if currentContainer.IsGaudiManaged() {
			hasGaudiManagedContainer = true
			currentContainer.Image = "gaudi/" + name
		}

		for _, dependency := range currentContainer.Links {
			if depContainer, exists := collection[dependency]; exists {
				currentContainer.AddDependency(depContainer)
			} else {
				util.LogError(name + " references a non existing application : " + dependency)
			}
		}

		// Add relative path to volumes
		for volumeHost, volumeContainer := range currentContainer.Volumes {
			// Relative volume host
			if string(volumeHost[0]) != "/" {
				delete(currentContainer.Volumes, volumeHost)
				volumeHost = relativePath + "/" + volumeHost

				currentContainer.Volumes[volumeHost] = volumeContainer
			}

			// Create directory if needed
			if !util.IsDir(volumeHost) {
				err := os.MkdirAll(volumeHost, 0755)
				if err != nil {
					util.LogError(err)
				}
			}
		}
	}

	return hasGaudiManagedContainer
}
开发者ID:hungld,项目名称:gaudi,代码行数:43,代码来源:containerCollection.go


示例12: retrieveConfigPath

func retrieveConfigPath(configFile string) string {
	if len(configFile) == 0 {
		util.LogError("Config file name cannot be empty.")
	}

	if string(configFile[0]) != "/" {
		currentDir, err := os.Getwd()
		if err != nil {
			util.LogError(err)
		}

		configFile = currentDir + "/" + configFile
	}

	if !util.IsFile(configFile) {
		util.LogError("Configuration file not found: '" + configFile + "'. Use --config to specify a custom file")
	}

	return configFile
}
开发者ID:hungld,项目名称:gaudi,代码行数:20,代码来源:main.go


示例13: InitFromFile

func (gaudi *Gaudi) InitFromFile(file string) {
	gaudi.ConfigurationPath = file
	gaudi.ApplicationDir = path.Dir(file)

	fileContent, err := ioutil.ReadFile(file)
	if err != nil {
		util.LogError(err)
	}

	gaudi.Init(string(fileContent))
}
开发者ID:hungld,项目名称:gaudi,代码行数:11,代码来源:gaudi.go


示例14: retrieveTemplates

func retrieveTemplates() {
	os.MkdirAll(TEMPLATE_DIR, 0755)

	archive, err := os.Create(TEMPLATE_DIR + "templates.tar")
	if err != nil {
		util.LogError(err)
	}
	defer archive.Close()

	content, err := http.Get(TEMPLATE_REMOTE_PATH)
	if err != nil {
		util.LogError(err)
	}
	defer content.Body.Close()

	_, err = io.Copy(archive, content.Body)
	if err != nil {
		util.LogError(err)
	}
}
开发者ID:hungld,项目名称:gaudi,代码行数:20,代码来源:gaudi.go


示例15: extractTemplates

func extractTemplates() {
	tarFile, _ := os.Open(TEMPLATE_DIR + "templates.tar")
	defer tarFile.Close()

	tar := tar.NewReader(tarFile)

	for {
		header, err := tar.Next()
		if err == io.EOF {
			break
		}

		if err != nil {
			util.LogError(err)
		}

		// Remove first path part
		filePath := strings.Join(strings.Split(header.Name, "/")[1:], "/")

		// Check if we should create a folder or a file
		if header.Size == 0 {
			err := os.MkdirAll(TEMPLATE_DIR+filePath, 0755)
			if err != nil {
				util.LogError(err)
			}
		} else {
			f, err := os.Create(TEMPLATE_DIR + filePath)
			if err != nil {
				util.LogError(err)
			}
			defer f.Close()

			_, err = io.Copy(f, tar)
			if err != nil {
				util.LogError(err)
			}
		}
	}

	os.Remove(TEMPLATE_DIR + "templates.tar")
}
开发者ID:hungld,项目名称:gaudi,代码行数:41,代码来源:gaudi.go


示例16: Pull

func Pull(name string) {
	pullCmd := exec.Command(getDockerBinaryPath(), "pull", name)
	pullCmd.Stderr = os.Stderr
	pullCmd.Stdin = os.Stdin

	util.Debug("Pull command:", pullCmd.Args)

	if err := pullCmd.Run(); err != nil {
		util.LogError(err)
	}

	pullCmd.Wait()
}
开发者ID:hungld,项目名称:gaudi,代码行数:13,代码来源:docker.go


示例17: startOne

func startOne(currentContainer *container.Container, rebuild bool, done map[string]chan bool) {
	// Waiting for dependencies to be started
	for _, dependency := range currentContainer.Dependencies {
		if dependency.Name == currentContainer.Name {
			util.LogError("Application " + currentContainer.Name + " can't be linked with itself.")
		}

		<-done[dependency.Name]
	}

	currentContainer.Start(rebuild)

	close(done[currentContainer.Name])
}
开发者ID:hungld,项目名称:gaudi,代码行数:14,代码来源:containerCollection.go


示例18: Enter

func Enter(name string) {
	var pid string
	var imageExists bool
	nsenter, _ := exec.LookPath("nsenter")

	ps, _ := SnapshotProcesses()
	if pid, imageExists = ps[name]; !imageExists {
		util.LogError("Image " + name + " doesn't exists")
	}

	statePidBuff, _ := Inspect(pid, "--format", "{{.State.Pid}}")
	statePid := strings.TrimSpace(string(statePidBuff))

	enterCmd := exec.Command("sudo", nsenter, "--target", statePid, "--mount", "--uts", "--ipc", "--net", "--pid")
	enterCmd.Stdout = os.Stdout
	enterCmd.Stdin = os.Stdin
	enterCmd.Stderr = os.Stderr

	util.Debug("Run command:", enterCmd.Args)

	if err := enterCmd.Run(); err != nil {
		util.LogError(err)
	}
}
开发者ID:hungld,项目名称:gaudi,代码行数:24,代码来源:docker.go


示例19: Enter

/**
 * Enter in a specific container
 */
func (gaudi *Gaudi) Enter(name string) {
	// Check if nsenter exists
	images, err := docker.GetImages()
	if err != nil {
		util.LogError(err)
	}

	if _, ok := images["jpetazzo/nsenter"]; !ok {
		// Pull ns-enter image
		util.PrintGreen("Retrieving ns-enter image ...")
		docker.Exec([]string{"run", "--rm", "-v", "/usr/local/bin:/target", "jpetazzo/nsenter"}, false)
	}

	container := gaudi.All[name]
	docker.Enter(container.GetFullName())
}
开发者ID:hungld,项目名称:gaudi,代码行数:19,代码来源:gaudi.go


示例20: Exec

func Exec(args []string, hasStdout bool) {
	execFunc := reflect.ValueOf(exec.Command)
	execCmd := execFunc.Call(util.BuildReflectArguments(args))[0].Interface().(*exec.Cmd)

	if hasStdout {
		execCmd.Stdout = os.Stdout
	}

	execCmd.Stdin = os.Stdin
	execCmd.Stderr = os.Stderr

	util.Debug("Exec command:", execCmd.Args)

	if err := execCmd.Start(); err != nil {
		util.LogError(err)
	}
}
开发者ID:hungld,项目名称:gaudi,代码行数:17,代码来源:docker.go



注:本文中的github.com/marmelab/gaudi/util.LogError函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang util.MOCK函数代码示例发布时间:2022-05-23
下一篇:
Golang maestro.Maestro类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap