本文整理汇总了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, §, 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()
}
示例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, §)
}
}
}
}