You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

decoder.go 736B

12345678910111213141516171819202122232425262728293031323334353637
  1. package config
  2. import (
  3. "io"
  4. "github.com/go-git/gcfg"
  5. )
  6. // A Decoder reads and decodes config files from an input stream.
  7. type Decoder struct {
  8. io.Reader
  9. }
  10. // NewDecoder returns a new decoder that reads from r.
  11. func NewDecoder(r io.Reader) *Decoder {
  12. return &Decoder{r}
  13. }
  14. // Decode reads the whole config from its input and stores it in the
  15. // value pointed to by config.
  16. func (d *Decoder) Decode(config *Config) error {
  17. cb := func(s string, ss string, k string, v string, bv bool) error {
  18. if ss == "" && k == "" {
  19. config.Section(s)
  20. return nil
  21. }
  22. if ss != "" && k == "" {
  23. config.Section(s).Subsection(ss)
  24. return nil
  25. }
  26. config.AddOption(s, ss, k, v)
  27. return nil
  28. }
  29. return gcfg.ReadWithCallback(d, cb)
  30. }