towards moving config into context
This commit is contained in:
parent
b94b448f08
commit
6ef29819c7
7 changed files with 17 additions and 80 deletions
|
|
@ -1,52 +0,0 @@
|
|||
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