Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
| 1 |
package config |
| 2 |
|
| 3 |
import ( |
| 4 |
"io" |
| 5 |
|
| 6 |
"github.com/go-git/gcfg" |
| 7 |
) |
| 8 |
|
| 9 |
// A Decoder reads and decodes config files from an input stream. |
| 10 |
type Decoder struct { |
| 11 |
io.Reader |
| 12 |
} |
| 13 |
|
| 14 |
// NewDecoder returns a new decoder that reads from r. |
| 15 |
func NewDecoder(r io.Reader) *Decoder { |
| 16 |
return &Decoder{r} |
| 17 |
} |
| 18 |
|
| 19 |
// Decode reads the whole config from its input and stores it in the |
| 20 |
// value pointed to by config. |
| 21 |
func (d *Decoder) Decode(config *Config) error { |
| 22 |
cb := func(s string, ss string, k string, v string, bv bool) error { |
| 23 |
if ss == "" && k == "" { |
| 24 |
config.Section(s) |
| 25 |
return nil |
| 26 |
} |
| 27 |
|
| 28 |
if ss != "" && k == "" { |
| 29 |
config.Section(s).Subsection(ss) |
| 30 |
return nil |
| 31 |
} |
| 32 |
|
| 33 |
config.AddOption(s, ss, k, v) |
| 34 |
return nil |
| 35 |
} |
| 36 |
return gcfg.ReadWithCallback(d, cb) |
| 37 |
} |