Revert "towards moving config into context"

This reverts commit 7427716ea8.
This commit is contained in:
nate smith 2019-10-14 11:02:04 -05:00
parent 6ef29819c7
commit cccb6832c3
7 changed files with 80 additions and 17 deletions

52
github/config_encoder.go Normal file
View 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
}