@@ -0,0 +1,54 @@
|
||||
package ceph
|
||||
|
||||
import (
|
||||
"io/fs"
|
||||
"log"
|
||||
|
||||
"asciigoat.org/ini/basic"
|
||||
"darvaza.org/core"
|
||||
)
|
||||
|
||||
func loadConfSection(out *Config, src *basic.Section) error {
|
||||
switch src.Key {
|
||||
case "global":
|
||||
return loadGlobalConfSection(out, src)
|
||||
default:
|
||||
return core.Wrapf(fs.ErrInvalid, "unknown section %q", src.Key)
|
||||
}
|
||||
}
|
||||
|
||||
func loadGlobalConfSection(out *Config, src *basic.Section) error {
|
||||
var cfg GlobalConfig
|
||||
|
||||
for _, field := range src.Fields {
|
||||
if err := loadGlobalConfField(&cfg, field); err != nil {
|
||||
return core.Wrap(err, "global")
|
||||
}
|
||||
}
|
||||
|
||||
out.Global = cfg
|
||||
return nil
|
||||
}
|
||||
|
||||
func loadGlobalConfField(_ *GlobalConfig, field basic.Field) error {
|
||||
log.Printf("%s[%q] = %q", "global", field.Key, field.Value)
|
||||
return nil
|
||||
}
|
||||
|
||||
func newConfigFromDocument(doc *basic.Document) (*Config, error) {
|
||||
var out Config
|
||||
|
||||
if len(doc.Global) > 0 {
|
||||
err := core.Wrap(fs.ErrInvalid, "fields before the first section")
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for i := range doc.Sections {
|
||||
src := &doc.Sections[i]
|
||||
if err := loadConfSection(&out, src); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return &out, nil
|
||||
}
|
||||
Reference in New Issue
Block a user