Revert "towards moving config into context"
This reverts commit 7427716ea8.
This commit is contained in:
parent
6ef29819c7
commit
cccb6832c3
7 changed files with 80 additions and 17 deletions
52
github/config_encoder.go
Normal file
52
github/config_encoder.go
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
package github
|
||||
|
||||
import (
|
||||
"io"
|
||||
|
||||
"github.com/BurntSushi/toml"
|
||||
"gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
type configEncoder interface {
|
||||
Encode(w io.Writer, c *Config) error
|
||||
}
|
||||
|
||||
type tomlConfigEncoder struct {
|
||||
}
|
||||
|
||||
func (t *tomlConfigEncoder) Encode(w io.Writer, c *Config) error {
|
||||
enc := toml.NewEncoder(w)
|
||||
return enc.Encode(c)
|
||||
}
|
||||
|
||||
type yamlConfigEncoder struct {
|
||||
}
|
||||
|
||||
func (y *yamlConfigEncoder) Encode(w io.Writer, c *Config) error {
|
||||
yc := yaml.MapSlice{}
|
||||
for _, h := range c.Hosts {
|
||||
yc = append(yc, yaml.MapItem{
|
||||
Key: h.Host,
|
||||
Value: []yamlHost{
|
||||
{
|
||||
User: h.User,
|
||||
OAuthToken: h.AccessToken,
|
||||
Protocol: h.Protocol,
|
||||
UnixSocket: h.UnixSocket,
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
d, err := yaml.Marshal(yc)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
n, err := w.Write(d)
|
||||
if err == nil && n < len(d) {
|
||||
err = io.ErrShortWrite
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue