当前位置: 首页>>代码示例>>Golang>>正文


Golang config.GetConfig函数代码示例

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


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

示例1: init

func init() {
	noderoot = config.GetConfig(config.NODEROOT)
	nodehome = os.Getenv(NODE_HOME)
	if nodehome == "" && config.GetConfig(config.GLOBAL_VERSION) == util.UNKNOWN {
		P(NOTICE, "not found environment variable '%v', please use '%v'. See '%v'.\n", NODE_HOME, "gnvm reg noderoot", "gnvm help reg")
	}
}
开发者ID:Kenshin,项目名称:gnvm,代码行数:7,代码来源:regedit.go

示例2: Update

/*
 Update local Node.js latest verion

 - localVersion, remoteVersion: string  Node.js version
 - local, remote:               float64 Node.js version

 Param:
 	- global: when global == true, call Use func.

*/
func Update(global bool) {

	// try catch
	defer func() {
		if err := recover(); err != nil {
			msg := fmt.Sprintf("'%v' an error has occurred. \nError: ", "gnvm updte latest")
			Error(ERROR, msg, err)
			os.Exit(0)
		}
	}()

	localVersion, remoteVersion := config.GetConfig(config.LATEST_VERSION), util.GetLatVer(latURL)

	P(NOTICE, "local  Node.js latest version is %v.\n", localVersion)
	if remoteVersion == "" {
		P(ERROR, "get latest version error, please check. See '%v'.\n", "gnvm help config")
		return
	}
	P(NOTICE, "remote Node.js latest version is %v from %v.\n", remoteVersion, config.GetConfig("registry"))

	local, remote, args := util.FormatNodeVer(localVersion), util.FormatNodeVer(remoteVersion), []string{remoteVersion}

	switch {
	case localVersion == util.UNKNOWN:
		if code := InstallNode(args, global); code == 0 {
			config.SetConfig(config.LATEST_VERSION, remoteVersion)
			P(DEFAULT, "Update Node.js latest success, current latest version is %v.\n", remoteVersion)
		}
	case local == remote:
		if util.IsDirExist(rootPath + localVersion) {
			cp := CP{Red, false, None, false, "="}
			P(DEFAULT, "Remote latest version %v %v latest version %v, don't need to upgrade.\n", remoteVersion, cp, localVersion)
			if global {
				if ok := Use(localVersion); ok {
					config.SetConfig(config.GLOBAL_VERSION, localVersion)
				}
			}
		} else {
			P(WARING, "%v folder is not exist. See '%v'.\n", localVersion, "gnvm ls")
			if code := InstallNode(args, global); code == 0 {
				P(DEFAULT, "Local Node.js latest version is %v.\n", localVersion)
			}
		}
	case local > remote:
		cp := CP{Red, false, None, false, ">"}
		P(WARING, "local latest version %v %v remote latest version %v.\nPlease check your config %v. See '%v'.\n", localVersion, cp, remoteVersion, "registry", "gnvm help config")
	case local < remote:
		cp := CP{Red, false, None, false, ">"}
		P(WARING, "remote latest version %v %v local latest version %v.\n", remoteVersion, cp, localVersion)
		if code := InstallNode(args, global); code == 0 {
			config.SetConfig(config.LATEST_VERSION, remoteVersion)
			P(DEFAULT, "Update success, Node.js latest version is %v.\n", remoteVersion)
		}
	}
}
开发者ID:Kenshin,项目名称:gnvm,代码行数:65,代码来源:nodehandle.go

示例3: NodeVersion

func NodeVersion(args []string, remote bool) {

	// try catch
	defer func() {
		if err := recover(); err != nil {
			msg := fmt.Sprintf("'gnvm node-version %v' an error has occurred. please check. \nError: ", strings.Join(args, " "))
			Error(ERROR, msg, err)
			os.Exit(0)
		}
	}()

	latest := config.GetConfig(config.LATEST_VERSION)
	global := config.GetConfig(config.GLOBAL_VERSION)

	if len(args) == 0 || len(args) > 1 {
		P(DEFAULT, "Node.exe %v version is %v.\n", "latest", latest)
		P(DEFAULT, "Node.exe %v version is %v.\n", "global", global)
	} else {
		switch {
		case args[0] == "global":
			P(DEFAULT, "Node.exe global version is %v.\n", global)
		case args[0] == "latest" && !remote:
			P(DEFAULT, "Node.exe latest version is %v.\n", latest)
		case args[0] == "latest" && remote:
			remoteVersion := getLatestVersionByRemote()
			if remoteVersion == "" {
				P(ERROR, "get remote %v latest version error, please check. See '%v'.\n", config.GetConfig("registry")+config.LATEST+"/"+config.NODELIST, "gnvm help config")
				P(DEFAULT, "Node.exe latest version is %v.\n", latest)
				return
			}
			P(DEFAULT, "Node.exe remote %v version is %v.\n", config.GetConfig("registry"), remoteVersion)
			P(DEFAULT, "Node.exe latest version is %v.\n", latest)
		}
	}

	isPrint := false
	switch {
	case len(args) == 0 && (global == config.UNKNOWN || latest == config.UNKNOWN):
		isPrint = true
	case len(args) > 0 && args[0] == "latest" && latest == config.UNKNOWN:
		isPrint = true
	case len(args) > 0 && args[0] == "global" && global == config.UNKNOWN:
		isPrint = true
	}
	if isPrint {
		P(WARING, "when version is %v, please use '%v'. See '%v'.\n", config.UNKNOWN, "gnvm config INIT", "gnvm help config")
	}
}
开发者ID:GitHanDong,项目名称:gnvm,代码行数:48,代码来源:nodehandle.go

示例4: TransLatestVersion

func TransLatestVersion(latest string, isPrint bool) string {
	if latest == config.LATEST {
		latest = config.GetConfig(config.LATEST_VERSION)
		if isPrint {
			P(NOTICE, "current latest version is %v.\n", latest)
		}
	}
	return latest
}
开发者ID:GitHanDong,项目名称:gnvm,代码行数:9,代码来源:nodehandle.go

示例5: New

/*
 Create NPMange
*/
func (this *NPMange) New() *NPMange {
	this.root = config.GetConfig(config.NODEROOT)
	this.modules = this.root + util.DIVIDE + "node_modules"
	this.npmpath = this.modules + util.DIVIDE + util.NPM
	this.npmbin = this.npmpath + util.DIVIDE + "bin"
	this.command1 = "npm"
	this.command2 = "npm.cmd"
	return this
}
开发者ID:Kenshin,项目名称:gnvm,代码行数:12,代码来源:npm.go

示例6: downloadNpm

/*
 * return code
 * 0: success
 *
 */
func downloadNpm(version string) int {

	// set url
	url := config.GetConfig(config.REGISTRY) + "npm/" + version

	// download
	if code := curl.New(url, version, os.TempDir()+DIVIDE+version); code != 0 {
		return code
	}

	return 0
}
开发者ID:GitHanDong,项目名称:gnvm,代码行数:17,代码来源:nodehandle.go

示例7: getLatestVersionByRemote

func getLatestVersionByRemote() string {

	var version string

	// set url
	url := config.GetConfig("registry") + "latest/" + util.SHASUMS

	version = util.GetLatestVersion(url)

	return version

}
开发者ID:GitHanDong,项目名称:gnvm,代码行数:12,代码来源:nodehandle.go

示例8: LsRemote

func LsRemote() {

	// set url
	url := config.GetConfig(config.REGISTRY) + config.NODELIST

	// try catch
	defer func() {
		if err := recover(); err != nil {
			msg := fmt.Sprintf("'gnvm ls --remote' an error has occurred. please check registry %v. \nError: ", url)
			Error(ERROR, msg, err)
			os.Exit(0)
		}
	}()

	// set exist version
	isExistVersion := false

	// print
	P(DEFAULT, "Read all node.exe version list from %v, please wait.\n", url)

	// get
	code, res, _ := curl.Get(url)
	if code != 0 {
		return
	}
	// close
	defer res.Body.Close()

	writeVersion := func(content string, line int) bool {
		// replace '\n'
		content = strings.Replace(content, "\n", "", -1)

		// split 'vx.xx.xx  1.1.0-alpha-2'
		args := strings.Split(content, " ")

		if ok := util.VerifyNodeVersion(args[0][1:]); ok {
			isExistVersion = true
			P(DEFAULT, args[0], "\n")
		}
		return false
	}

	if err := curl.ReadLine(res.Body, writeVersion); err != nil && err != io.EOF {
		P(ERROR, "%v Error: %v\n", "gnvm ls --remote", err)
	}

}
开发者ID:GitHanDong,项目名称:gnvm,代码行数:47,代码来源:nodehandle.go

示例9: Search

/*
 Search Node.js version and Print

 Param:
 	- s: Node.js version, inlcude: *.*.* 0.*.* 0.10.* /<regexp>/ latest 0.10.10

*/
func Search(s string) {
	regex, err := util.FormatWildcard(s, latURL)
	if err != nil {
		P(ERROR, "%v not an %v Node.js version.\n", s, "valid")
		return
	}

	// set url
	url := config.GetConfig(config.REGISTRY)
	if arr := strings.Split(s, "."); len(arr) == 3 {
		if ver, _ := strconv.Atoi(arr[0]); ver >= 1 && ver <= 3 {
			url = config.GetIOURL(url)
		}
	}
	url += util.NODELIST

	// try catch
	defer func() {
		if err := recover(); err != nil {
			msg := fmt.Sprintf("'%v' an error has occurred. please check your input.\nError: ", "gnvm search")
			Error(ERROR, msg, err)
			os.Exit(0)
		}
	}()

	// print
	P(DEFAULT, "Search Node.js version rules [%v] from %v, please wait.\n", s, url)

	// generate nodist
	nodist, err, code := New(url, regex)
	if err != nil {
		if code == -1 {
			P(ERROR, "'%v' get url %v error, Error: %v\n", "gnvm search", url, err)
		} else {
			P(ERROR, "%v an error has occurred. please check. Error: %v\n", "gnvm search", err)
		}
		return
	}

	if len(nodist.nl) > 0 {
		nodist.Detail(0)
	} else {
		P(WARING, "not search any Node.js version details, use rules [%v] from %v.\n", s, url)
	}
}
开发者ID:Kenshin,项目名称:gnvm,代码行数:52,代码来源:nodehandle.go

示例10: getNodeNpmVer

/*
 Get npm version by global( local ) node version

 Return:
    - string: npm version

*/
func getNodeNpmVer() string {
	ver, err := util.GetNodeVer(rootPath)
	if err != nil {
		panic(errors.New("not exist global node.exe. please usage 'gnvm install latest -g' frist."))
	}

	url := config.GetConfig(config.REGISTRY)
	if level := util.GetNodeVerLev(util.FormatNodeVer(ver)); level == 3 {
		url = config.GetIOURL(url)
	}
	url += util.NODELIST

	nd, err := FindNodeDetailByVer(url, ver)
	if err != nil {
		panic(err)
	}
	return nd.NPM.Version
}
开发者ID:Kenshin,项目名称:gnvm,代码行数:25,代码来源:npm.go

示例11: download

/*
 * return code
 * 0: success
 * 1: remove folder error
 * 2: folder exist
 * 3: create folder error
 *
 */
func download(version string) int {

	// get current os arch
	amd64 := "/"
	if runtime.GOARCH == "amd64" {
		amd64 = "/x64/"
	}

	// rootPath/version/node.exe is exist
	if _, err := util.GetNodeVersion(rootPath + version + DIVIDE); err == nil {
		P(WARING, "%v folder exist.\n", version)
		return 2
	} else {
		if err := os.RemoveAll(rootPath + version); err != nil {
			P(ERROR, "remove %v fail, Error: %v\n", version, err.Error())
			return 1
		}
		//P(DEFAULT, "Remove empty [%v] folder success.\n", version)
	}

	// rootPath/version is exist
	if isDirExist(rootPath+version) != true {
		if err := os.Mkdir(rootPath+version, 0777); err != nil {
			P(ERROR, "create %v fail, Error: %v\n", version, err.Error())
			return 3
		}
	}

	// set url
	url := config.GetConfig(config.REGISTRY) + "v" + version + amd64 + NODE

	// download
	if code := curl.New(url, version, rootPath+version+DIVIDE+NODE); code != 0 {
		if code == -1 {
			if err := os.RemoveAll(rootPath + version); err != nil {
				P(ERROR, "remove %v fail, Error: %v\n", version, err.Error())
				return 1
			}
		}
		return code
	}

	return 0
}
开发者ID:GitHanDong,项目名称:gnvm,代码行数:52,代码来源:nodehandle.go

示例12: downloadNpm

/*
 Download / unzip / install npm

 Param:
    - ver: npm version

*/
func downloadNpm(ver string) {
	version := "v" + ver + ZIP
	url := NPMTAOBAO + version
	if config.GetConfig(config.REGISTRY) != util.ORIGIN_TAOBAO {
		url = NPMDEFAULT + version
	}

	// create npm
	npm.New().SetZip(version)

	P(DEFAULT, "Start download new npm version %v\n", version)

	// download
	if err := npm.Download(url, version); err != nil {
		panic(err.Error())
	}

	P(DEFAULT, "Start unzip and install %v zip file, please wait.\n", version)

	// create node_modules
	npm.CreateModules()

	// clean all npm files
	npm.CleanAll()

	// unzip
	if _, err := npm.Unzip(); err != nil {
		msg := fmt.Sprintf("unzip %v an error has occurred. \nError: ", npm.zipname, err.Error())
		panic(errors.New(msg))
	}

	// install
	if err := npm.Install(); err != nil {
		return
	}

	// remove download zip file
	npm.Clean(npm.zippath)

	P(DEFAULT, "Set success, current npm version is %v.\n", ver)
}
开发者ID:Kenshin,项目名称:gnvm,代码行数:48,代码来源:npm.go

示例13: LsRemote

/*
 Print remote Node.js version list

 Param:
 	- limit: print max line
 	- io:    when io == true, print iojs

*/
func LsRemote(limit int, io bool) {
	// set url
	url := config.GetConfig(config.REGISTRY)
	if io {
		url = config.GetIOURL(url)
	}
	url += util.NODELIST

	// try catch
	defer func() {
		if err := recover(); err != nil {
			msg := fmt.Sprintf("'gnvm ls --remote' an error has occurred. please check your input %v. \nError: ", url)
			Error(ERROR, msg, err)
			os.Exit(0)
		}
	}()

	// print
	P(DEFAULT, "Read all Node.js version list from %v, please wait.\n", url)

	// generate nodist
	nodist, err, code := New(url, nil)
	if err != nil {
		if code == -1 {
			P(ERROR, "'%v' get url %v error, Error: %v\n", "gnvm ls -r -d", url, err)
		} else {
			P(ERROR, "%v an error has occurred. please check your input. Error: %v\n", "gnvm ls -r -d", err)
		}
		return
	}

	if limit != -1 {
		nodist.Detail(limit)
	} else {
		for _, v := range nodist.Sorts {
			fmt.Println(v)
		}
	}
}
开发者ID:Kenshin,项目名称:gnvm,代码行数:47,代码来源:nodehandle.go

示例14:

			v = util.EqualAbs("npm", v)
			if v == "npm" {
				nodehandle.UninstallNPM()
				continue
			}

			v = util.EqualAbs("ALL", v)
			if v == "ALL" {
				P(WARING, "'%v' not supported mixed parameters, please usage '%v'. See '%v'.\n", "gnvm uninstall ALL", "gnvm uninstall ALL", "gnvm help uninstall")
				continue
			}

			v = util.EqualAbs("latest", v)
			if v == util.LATEST {
				util.FormatLatVer(&v, config.GetConfig(config.LATEST_VERSION), true)
			}

			// check version format
			if !util.VerifyNodeVer(v) {
				P(ERROR, "%v not an %v Node.js version.\n", v, "valid")
			} else {
				nodehandle.Uninstall(v)
			}
		}
	},
}

// sub cmd
var useCmd = &cobra.Command{
	Use:   "use",
开发者ID:Kenshin,项目名称:gnvm,代码行数:30,代码来源:command.go

示例15: Update

func Update(global bool) {

	// try catch
	defer func() {
		if err := recover(); err != nil {
			Error(ERROR, "'gnvm updte latest' an error has occurred. \nError: ", err)
			os.Exit(0)
		}
	}()

	localVersion := config.GetConfig(config.LATEST_VERSION)
	P(NOTICE, "local latest version is %v.\n", localVersion)

	remoteVersion := getLatestVersionByRemote()
	if remoteVersion == "" {
		P(ERROR, "get latest version error, please check. See '%v'.\n", "gnvm help config")
		return
	}
	P(NOTICE, "remote %v latest version is %v.\n", config.GetConfig("registry"), remoteVersion)

	local, _ := util.ConverFloat(localVersion)
	remote, _ := util.ConverFloat(remoteVersion)

	var args []string
	args = append(args, remoteVersion)

	switch {
	case localVersion == config.UNKNOWN:
		P(WARING, "local latest version is %v.\n", config.UNKNOWN)
		if code := Install(args, global); code == 0 || code == 2 {
			config.SetConfig(config.LATEST_VERSION, remoteVersion)
			P(DEFAULT, "Update latest success, current latest version is %v.\n", remoteVersion)
		}
	case local == remote:

		if isDirExist(rootPath + localVersion) {
			cp := CP{Red, false, None, false, "="}
			P(DEFAULT, "Remote latest version %v %v latest version %v, don't need to upgrade.\n", remoteVersion, cp, localVersion)
			if global {
				if ok := Use(localVersion); ok {
					config.SetConfig(config.GLOBAL_VERSION, localVersion)
				}
			}
		} else if !isDirExist(rootPath + localVersion) {
			P(WARING, "local not exist %v\n", localVersion)
			if code := Install(args, global); code == 0 || code == 2 {
				P(DEFAULT, "Download latest version %v success.\n", localVersion)
			}
		}

	case local > remote:
		cp := CP{Red, false, None, false, ">"}
		P(WARING, "local latest version %v %v remote latest version %v.\nPlease check your registry. See 'gnvm help config'.\n", localVersion, cp, remoteVersion)
	case local < remote:
		cp := CP{Red, false, None, false, ">"}
		P(WARING, "remote latest version %v %v local latest version %v.\n", remoteVersion, cp, localVersion)
		if code := Install(args, global); code == 0 || code == 2 {
			config.SetConfig(config.LATEST_VERSION, remoteVersion)
			P(DEFAULT, "Update latest success, current latest version is %v.\n", remoteVersion)
		}
	}
}
开发者ID:GitHanDong,项目名称:gnvm,代码行数:62,代码来源:nodehandle.go


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