本文整理汇总了Golang中github.com/Unknwon/goconfig.ConfigFile类的典型用法代码示例。如果您正苦于以下问题:Golang ConfigFile类的具体用法?Golang ConfigFile怎么用?Golang ConfigFile使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ConfigFile类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: runRun
func runRun(ctx *cli.Context) {
setup(ctx)
//support unix only
if ctx.Bool("local") {
var localPath string
var err error
var wd string
var gf *goconfig.ConfigFile
wd, _ = os.Getwd()
for wd != "/" {
gf, _ = goconfig.LoadConfigFile(".gopmfile")
if gf != nil {
localPath = gf.MustValue("project", "localPath")
}
if localPath != "" {
break
}
os.Chdir("..")
wd, _ = os.Getwd()
}
if wd == "/" {
log.Fatal("run", "no gopmfile in the directory or parent directory")
}
argss := gf.MustValue("run", "cmd")
if localPath == "" {
log.Fatal("run", "No localPath set")
}
args := strings.Split(argss, " ")
argsLen := len(args)
for i := 0; i < argsLen; i++ {
strings.Trim(args[i], " ")
}
if len(args) < 2 {
log.Fatal("run", "cmd arguments less than 2")
}
err = execCmd(localPath, localPath, args...)
if err != nil {
log.Error("run", "Fail to run program:")
log.Fatal("", "\t"+err.Error())
}
return
}
// Get GOPATH.
installGopath = com.GetGOPATHs()[0]
if com.IsDir(installGopath) {
isHasGopath = true
log.Log("Indicated GOPATH: %s", installGopath)
installGopath += "/src"
}
// run command with gopm repos context
// need version control , auto link to GOPATH/src repos
genNewGoPath(ctx, false)
defer os.RemoveAll(doc.VENDOR)
log.Trace("Running...")
cmdArgs := []string{"go", "run"}
cmdArgs = append(cmdArgs, ctx.Args()...)
err := execCmd(newGoPath, newCurPath, cmdArgs...)
if err != nil {
log.Error("run", "Fail to run program:")
log.Fatal("", "\t"+err.Error())
}
log.Success("SUCC", "run", "Command executed successfully!")
}
示例7: 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
}
示例8: 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.
//.........这里部分代码省略.........
示例9: LoadBangoConfig
func LoadBangoConfig(fileName string) {
var err error
_, err = os.Stat(fileName)
if err != nil {
if os.IsNotExist(err) {
panic("Configuration file does not exists: " + err.Error())
} else {
panic("Something wrong with configuration file: " + err.Error())
}
}
var cfg *goconfig.ConfigFile
cfg, err = goconfig.LoadConfigFile(fileName)
if err != nil {
panic("Fail to load configuration file: " + err.Error())
}
// Parse the global section
config.global.debug = cfg.MustBool("global", "debug", false)
// Parse the redis section
config.redis.server = cfg.MustValue("redis", "server", "localhost")
config.redis.port = cfg.MustValue("redis", "port", "6379")
config.redis.db = cfg.MustInt("redis", "db", 0)
config.redis.pass = cfg.MustValue("redis", "pass", "")
// Parse the fail2ban section
config.fail2ban.channel = cfg.MustValue("fail2ban", "channel", "fail2ban")
config.fail2ban.jail = cfg.MustValue("fail2ban", "jail", "fail2ban-recidive")
config.fail2ban.useF2C = cfg.MustBool("fail2ban", "usef2bclient", true)
}