本文整理汇总了Golang中github.com/Unknwon/goconfig.ConfigFile.GetValue方法的典型用法代码示例。如果您正苦于以下问题:Golang ConfigFile.GetValue方法的具体用法?Golang ConfigFile.GetValue怎么用?Golang ConfigFile.GetValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/Unknwon/goconfig.ConfigFile
的用法示例。
在下文中一共展示了ConfigFile.GetValue方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: setField
func (i *INILoader) setField(field *structs.Field, c *goconfig.ConfigFile, section string) error {
//first process each subfield of a struct field
switch field.Kind() {
case reflect.Struct:
for _, f := range field.Fields() {
var subsection string
if section == "" {
subsection = field.Name()
} else {
subsection = section + "." + field.Name()
}
if err := i.setField(f, c, subsection); err != nil {
return err
}
}
default:
v, err := c.GetValue(section, field.Name())
if err == nil && v != "" {
err := fieldSet(field, v)
if err != nil {
return err
}
}
}
return nil
}
示例2: GetLocal
func GetLocal(c *goconfig.ConfigFile) map[string]string {
local := make(map[string]string)
dir := c.GetKeyList("local")
for _, v := range dir {
row, _ := c.GetValue("local", v)
local[strings.Trim(v, "#")] = row
}
return local
}
示例3: GetHost
func GetHost(c *goconfig.ConfigFile) map[string][]string {
server := make(map[string][]string)
host := c.GetKeyList("host")
for _, v := range host {
row, _ := c.GetValue("host", v)
server[strings.Trim(v, "#")] = strings.Split(row, "`")
}
return server
}
示例4: GetGlobal
func GetGlobal(c *goconfig.ConfigFile) map[string]string {
global := make(map[string]string)
cmds := c.GetKeyList("global")
for _, v := range cmds {
row, _ := c.GetValue("global", v)
global[strings.Trim(v, "#")] = row
}
return global
}
示例5: config
func config(cfg *goconfig.ConfigFile, section string, key string, lvl level) string {
value, err := cfg.GetValue(section, key)
if err != nil {
switch lvl {
case FATAL:
logger.Critical("Can't Read config %s", err.Error())
panic(err.Error())
case ERROR:
logger.Error("Can't Read config %s", err.Error())
case WARMING:
logger.Warn("Can't Read config %s", err.Error())
case INFO:
logger.Info("Can't Read config %s", err.Error())
}
return ""
}
return value
}
示例6: NewDaemonFromDirectory
func NewDaemonFromDirectory(cfg *goconfig.ConfigFile) (*Daemon, error) {
kernel, _ := cfg.GetValue(goconfig.DEFAULT_SECTION, "Kernel")
initrd, _ := cfg.GetValue(goconfig.DEFAULT_SECTION, "Initrd")
glog.V(0).Infof("The config: kernel=%s, initrd=%s", kernel, initrd)
vboxImage, _ := cfg.GetValue(goconfig.DEFAULT_SECTION, "Vbox")
glog.V(0).Infof("The config: vbox image=%s", vboxImage)
biface, _ := cfg.GetValue(goconfig.DEFAULT_SECTION, "Bridge")
bridgeip, _ := cfg.GetValue(goconfig.DEFAULT_SECTION, "BridgeIP")
glog.V(0).Infof("The config: bridge=%s, ip=%s", biface, bridgeip)
bios, _ := cfg.GetValue(goconfig.DEFAULT_SECTION, "Bios")
cbfs, _ := cfg.GetValue(goconfig.DEFAULT_SECTION, "Cbfs")
glog.V(0).Infof("The config: bios=%s, cbfs=%s", bios, cbfs)
host, _ := cfg.GetValue(goconfig.DEFAULT_SECTION, "Host")
var tempdir = path.Join(utils.HYPER_ROOT, "run")
os.Setenv("TMPDIR", tempdir)
if err := os.MkdirAll(tempdir, 0755); err != nil && !os.IsExist(err) {
return nil, err
}
var realRoot = path.Join(utils.HYPER_ROOT, "lib")
// Create the root directory if it doesn't exists
if err := os.MkdirAll(realRoot, 0755); err != nil && !os.IsExist(err) {
return nil, err
}
var (
db_file = fmt.Sprintf("%s/hyper.db", realRoot)
)
db, err := daemondb.NewDaemonDB(db_file)
if err != nil {
return nil, err
}
daemon := &Daemon{
ID: fmt.Sprintf("%d", os.Getpid()),
db: db,
Kernel: kernel,
Initrd: initrd,
Bios: bios,
Cbfs: cbfs,
VboxImage: vboxImage,
PodList: NewPodList(),
VmList: NewVmList(),
Host: host,
BridgeIP: bridgeip,
BridgeIface: biface,
}
daemon.Daemon, err = docker.NewDaemon(dockerCfg, registryCfg)
if err != nil {
return nil, err
}
// Get the docker daemon info
sysinfo, err := daemon.Daemon.SystemInfo()
if err != nil {
return nil, err
}
stor, err := StorageFactory(sysinfo)
if err != nil {
return nil, err
}
daemon.Storage = stor
daemon.Storage.Init()
return daemon, nil
}
示例7: downloadPackages
// downloadPackages downloads packages with certain commit,
// if the commit is empty string, then it downloads all dependencies,
// otherwise, it only downloada package with specific commit only.
func downloadPackages(ctx *cli.Context, nodes []*doc.Node) {
// Check all packages, they may be raw packages path.
for _, n := range nodes {
// Check if local reference
if n.Type == doc.LOCAL {
continue
}
// Check if it is a valid remote path or C.
if n.ImportPath == "C" {
continue
} else if !doc.IsValidRemotePath(n.ImportPath) {
// Invalid import path.
log.Error("download", "Skipped invalid package: "+fmt.Sprintf("%[email protected]%s:%s",
n.ImportPath, n.Type, doc.CheckNodeValue(n.Value)))
failConut++
continue
}
// Valid import path.
gopathDir := path.Join(installGopath, n.ImportPath)
n.RootPath = doc.GetProjectPath(n.ImportPath)
installPath := path.Join(installRepoPath, n.RootPath) + versionSuffix(n.Value)
if isSubpackage(n.RootPath, ".") {
continue
}
// Indicates whether need to download package again.
if n.IsFixed() && com.IsExist(installPath) {
n.IsGetDepsOnly = true
}
if !ctx.Bool("update") {
// Check if package has been downloaded.
if (len(n.Value) == 0 && !ctx.Bool("remote") && com.IsExist(gopathDir)) ||
com.IsExist(installPath) {
log.Trace("Skipped installed package: %[email protected]%s:%s",
n.ImportPath, n.Type, doc.CheckNodeValue(n.Value))
// Only copy when no version control.
if ctx.Bool("gopath") && com.IsExist(installPath) ||
len(getVcsName(gopathDir)) == 0 {
copyToGopath(installPath, gopathDir)
}
continue
} else {
doc.LocalNodes.SetValue(n.RootPath, "value", "")
}
}
if downloadCache[n.RootPath] {
log.Trace("Skipped downloaded package: %[email protected]%s:%s",
n.ImportPath, n.Type, doc.CheckNodeValue(n.Value))
continue
}
// Download package.
nod, imports := downloadPackage(ctx, n)
if len(imports) > 0 {
var gf *goconfig.ConfigFile
// Check if has gopmfile.
if com.IsFile(installPath + "/" + doc.GOPM_FILE_NAME) {
log.Log("Found gopmfile: %[email protected]%s:%s",
n.ImportPath, n.Type, doc.CheckNodeValue(n.Value))
gf = doc.NewGopmfile(installPath)
}
// Need to download dependencies.
// Generate temporary nodes.
nodes := make([]*doc.Node, len(imports))
for i := range nodes {
nodes[i] = doc.NewNode(imports[i], imports[i], doc.BRANCH, "", true)
if gf == nil {
continue
}
// Check if user specified the version.
if v, err := gf.GetValue("deps", imports[i]); err == nil && len(v) > 0 {
nodes[i].Type, nodes[i].Value = validPath(v)
}
}
downloadPackages(ctx, nodes)
}
// Only save package information with specific commit.
if nod == nil {
continue
}
// Save record in local nodes.
log.Success("SUCC", "GET", fmt.Sprintf("%[email protected]%s:%s",
n.ImportPath, n.Type, doc.CheckNodeValue(n.Value)))
downloadCount++
// Only save non-commit node.
//.........这里部分代码省略.........