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

Golang utils.Context类代码示例

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

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



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

示例1: getFullContainerPath

func (self *VolumeV6) getFullContainerPath(context Utils.Context) (string, error) {
	if self.Container == "" {
		return "", errors.New("Undefined container path")
	} else {
		log.Debug("getFullContainerPath value ", self.Container)
		clean := containerFilepath.ToSlash(containerFilepath.Clean(self.Container))
		log.Debug("getFullContainerPath clean ", clean)
		if containerFilepath.IsAbs(clean) {
			log.Debug("getFullContainerPath isAbs")
			return clean, nil
		} else {
			log.Debug("getFullContainerPath is not Abs")
			log.Debug("getFullContainerPath return ", containerFilepath.Join(context.GetRootDirectory(), clean))
			return containerFilepath.Join(context.GetRootDirectory(), clean), nil
		}
	}
}
开发者ID:RobbieClarken,项目名称:nut,代码行数:17,代码来源:config_v6.go


示例2: FindProject

/// Look for a file from which to parse configuration (nut.yml in current
/// directory). Parse the file, and returns an updated context (root directory)
/// TODO: look for nut.yml file in parent folders
func FindProject(context Utils.Context) (Project, Utils.Context, error) {
	// var parentProject Project
	var project Project
	var err error
	var newContext Utils.Context
	var store Persist.Store

	foundDirectory := context.GetUserDirectory()
	// fullpath := filepath.Join(foundDirectory, NutFileName)
	fullpath := filepath.Join(foundDirectory, NutOverrideFileName)
	previousFoundDirectory := ""
	var exists bool

	searchHigher := true
	found := false
	for searchHigher == true {
		if exists, err = Utils.FileExists(fullpath); exists && err == nil {
			found = true
			searchHigher = false
		} else {
			fullpath = filepath.Join(foundDirectory, NutFileName)

			if exists, err = Utils.FileExists(fullpath); exists && err == nil {
				found = true
				searchHigher = false
			} else {
				previousFoundDirectory = foundDirectory
				foundDirectory = filepath.Dir(foundDirectory)
				// fullpath = filepath.Join(foundDirectory, NutFileName)
				fullpath = filepath.Join(foundDirectory, NutOverrideFileName)

				if foundDirectory == previousFoundDirectory {
					searchHigher = false
				}
			}
		}
	}

	if found {
		if project, err = LoadProjectFromFile(fullpath); err == nil {
			log.Debug("Parsed from file: ", fullpath)
			if newContext, err = Utils.NewContext(foundDirectory, context.GetUserDirectory()); err == nil {
				log.Debug("Context updated: ", newContext)
				if store, err = Persist.InitStore(newContext.GetRootDirectory()); err == nil {
					log.Debug("Store initialized: ", store)
					if err = ResolveDependencies(project, store, fullpath); err == nil {
						log.Debug("Resolved dependencies from file: ", fullpath)
						return project, newContext, err
					}
				}
			}
		}
	} else {
		err = errors.New("Could not find '" + NutFileName + "', neither in current directory nor in its parents.")
	}
	return nil, nil, err
}
开发者ID:RobbieClarken,项目名称:nut,代码行数:60,代码来源:utils.go


示例3: getFullHostPath

func (self *VolumeV6) getFullHostPath(context Utils.Context) (string, error) {
	if self.Host == "" {
		return "", errors.New("Undefined host path")
	} else {
		log.Debug("getFullHostPath value ", self.Host)
		res := filepath.Clean(self.Host)
		log.Debug("getFullHostPath clean ", res)
		if !filepath.IsAbs(res) {
			log.Debug("getFullHostPath is not Abs")
			res = filepath.Join(context.GetRootDirectory(), res)
		}
		log.Debug("getFullHostPath value ", res)
		if strings.Contains(res, `:\`) { // path on windows. Eg: C:\\Users\
			log.Debug("getFullHostPath windows ", `:\`)
			parts := strings.Split(res, `:\`)
			parts[0] = strings.ToLower(parts[0]) // drive letter should be lower case
			res = "//" + parts[0] + "/" + filepath.ToSlash(parts[1])
		}

		log.Debug("getFullHostPath res ", res)
		return res, nil
	}
}
开发者ID:RobbieClarken,项目名称:nut,代码行数:23,代码来源:config_v6.go


示例4: initSubcommand

// create a nut.yml at the current path
func initSubcommand(c *cli.Context, context Utils.Context, gitHubFlag string) {
	log.Debug("initSubcommand context: ", context)
	name := filepath.Base(context.GetUserDirectory())

	var project Config.Project
	if gitHubFlag == "" {
		defaultProject := Config.NewProjectV6(nil)
		defaultProject.ProjectName = name
		defaultProject.DockerImage = "golang:1.6"
		defaultProject.Macros["build"] = &Config.MacroV6{
			Usage:    "build the project in the container",
			Actions:  []string{"go build -o nut"},
			ConfigV6: *Config.NewConfigV6(nil),
		}
		defaultProject.Macros["run"] = &Config.MacroV6{
			Usage:    "run the project in the container",
			Actions:  []string{"./nut"},
			ConfigV6: *Config.NewConfigV6(nil),
		}
		project = defaultProject
	} else {
		if store, err := Persist.InitStore(context.GetUserDirectory()); err == nil {
			log.Debug("Store initialized: ", store)
			if filename, err := Config.DownloadFromGithub(gitHubFlag, store); err == nil {
				log.Debug("Downloaded from Github to ", filename)
				if parentProject, err := Config.LoadProjectFromFile(filename); err == nil {
					log.Debug("Parsed from Github: ", parentProject)
					if err = Config.ResolveDependencies(parentProject, store, filename); err == nil {
						log.Debug("Resolved dependencies from Github: ", filename)
						finalProject := Config.NewProjectV6(parentProject)
						finalProject.ProjectName = name
						finalProject.Base.GitHub = gitHubFlag

						// modified project depending on parent configuration
						// 1 - mount folder "." if not already mounted by parent configuration
						mountingPointName := "main"
						hostDir := "."
						containerDir := containerFilepath.Join("/nut", name)
						mountingPoint := &Config.VolumeV6{
							Host:      hostDir,
							Container: containerDir,
						}
						if Config.CheckConflict(context, mountingPointName, mountingPoint, Config.GetVolumes(finalProject, context)) == nil {
							finalProject.ConfigV6.Mount[mountingPointName] = []string{hostDir, containerDir}
						}
						// 2 - set working directory to "." if not specified otherwise
						if Config.GetWorkingDir(finalProject) == "" {
							finalProject.ConfigV6.WorkingDir = containerDir
						}

						project = finalProject
					}
				} else {
					log.Error("Error while parsing from GitHub: ", err)
				}
			} else {
				log.Error("Error while loading from GitHub: ", err)
			}
		} else {
			log.Error("Error while loading nut files: ", err)
		}
	}

	if project == nil {
		return
	}
	if data, err := Config.ToYAML(project); err != nil {
		log.Error("Could not generate default project configuration:", err)
	} else {
		fmt.Println("Project configuration:")
		fmt.Println("")
		dataString := string(data)
		fmt.Println(dataString)
		// check is nut.yml exists at the current path
		nutfileName := filepath.Join(context.GetUserDirectory(), Config.NutFileName) // TODO: pick this name from a well documented and centralized list of legit nut file names
		if exists, err := Utils.FileExists(nutfileName); exists && err == nil {
			log.Error("Could not save new Nut project because a nut.yml file already exists")
			return
		} else {
			err := ioutil.WriteFile(nutfileName, data, 0644) // TODO: discuss this permission level
			if err != nil {
				log.Error(err)
			} else {
				fmt.Println("Project configuration saved in %s.", nutfileName) // TODO: make sure that bug Project configuration saved in %!(EXTRA string=./nut.yml) is fixed.
			}
		}
	}
}
开发者ID:RobbieClarken,项目名称:nut,代码行数:89,代码来源:init.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang bot.Track类代码示例发布时间:2022-05-23
下一篇:
Golang pipe.ReadErrors函数代码示例发布时间: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