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


Golang File.Sections方法代码示例

本文整理汇总了Golang中github.com/go-ini/ini.File.Sections方法的典型用法代码示例。如果您正苦于以下问题:Golang File.Sections方法的具体用法?Golang File.Sections怎么用?Golang File.Sections使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/go-ini/ini.File的用法示例。


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

示例1: Backup

func Backup(log *logging.Logger, cfg *ini.File, grace string, reload bool) {
	const POOL = 5
	var db database.DB
	var tx *sql.Tx
	var c = make(chan bool, POOL)
	var wg = new(sync.WaitGroup)

	var dataset, maxdatasets int
	var sections []*ini.Section

	sections = cfg.Sections()

	maxdatasets, _ = cfg.Section("dataset").Key(grace).Int()

	db.Open(log, cfg)
	defer db.Close()

	tx, _ = db.Conn.Begin()
	dataset = database.GetDataset(log, tx, grace)
	tx.Commit()

	if !reload {
		if nextds := dataset + 1; nextds > maxdatasets {
			dataset = 1
		} else {
			dataset = dataset + 1
		}
	}
	log.Info("Dataset processed: " + strconv.Itoa(dataset))

	wg.Add(len(sections) - len(SECT_RESERVED))
	for _, section := range sections {
		if !contains(SECT_RESERVED, section.Name()) {
			if section.Key("type").String() == "file" { // FIXME: useless?
				sect := common.Section{
					Name:       section.Name(),
					Grace:      grace,
					Dataset:    dataset,
					Compressed: section.Key("compress").MustBool(),
				}

				go fileBackup(log, &sect, cfg, c, wg)
				c <- true
			}
		}
	}
	wg.Wait() // Wait for all the children to die
	close(c)

	tx, _ = db.Conn.Begin()
	database.SetDataset(log, tx, dataset, grace)
	tx.Commit()
}
开发者ID:mementobackup,项目名称:server,代码行数:53,代码来源:backup.go

示例2: Restore

func Restore(log *logging.Logger, cfg *ini.File, grace string) {
	dataset := cfg.Section("general").Key("dataset").MustInt()

	for _, section := range cfg.Sections() {
		if !contains(SECT_RESERVED, section.Name()) {
			if section.Key("type").String() == "file" {
				sect := common.Section{
					Name:       section.Name(),
					Grace:      grace,
					Dataset:    dataset,
					Compressed: section.Key("compress").MustBool(),
				}
				fileRestore(log, cfg, &sect)
			}
		}
	}
}
开发者ID:mementobackup,项目名称:server,代码行数:17,代码来源:restore.go


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