mirror of
https://gitea.com/gitea/tea.git
synced 2024-06-01 17:21:23 +05:30
6cff3b1cc7
Merge branch 'master' into vendor-migrate-go-git Merge branch 'master' into vendor-migrate-go-git migrate src-d/go-git -> go-git/go-git Co-authored-by: 6543 <6543@obermui.de> Reviewed-on: https://gitea.com/gitea/tea/pulls/128 Reviewed-by: techknowlogick <techknowlogick@gitea.io> Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
38 lines
736 B
Go
38 lines
736 B
Go
package config
|
|
|
|
import (
|
|
"io"
|
|
|
|
"github.com/go-git/gcfg"
|
|
)
|
|
|
|
// A Decoder reads and decodes config files from an input stream.
|
|
type Decoder struct {
|
|
io.Reader
|
|
}
|
|
|
|
// NewDecoder returns a new decoder that reads from r.
|
|
func NewDecoder(r io.Reader) *Decoder {
|
|
return &Decoder{r}
|
|
}
|
|
|
|
// Decode reads the whole config from its input and stores it in the
|
|
// value pointed to by config.
|
|
func (d *Decoder) Decode(config *Config) error {
|
|
cb := func(s string, ss string, k string, v string, bv bool) error {
|
|
if ss == "" && k == "" {
|
|
config.Section(s)
|
|
return nil
|
|
}
|
|
|
|
if ss != "" && k == "" {
|
|
config.Section(s).Subsection(ss)
|
|
return nil
|
|
}
|
|
|
|
config.AddOption(s, ss, k, v)
|
|
return nil
|
|
}
|
|
return gcfg.ReadWithCallback(d, cb)
|
|
}
|