Implement encoding.TextMarshaler interface

This commit is contained in:
Kevin Burke
2017-10-13 14:14:58 -07:00
parent db49ba357d
commit 802051befe
2 changed files with 11 additions and 2 deletions
+1
View File
@@ -0,0 +1 @@
/bazel-*
+10 -2
View File
@@ -274,12 +274,20 @@ func (c *Config) Get(alias, key string) (string, error) {
}
// String returns a string representation of the Config file.
func (c *Config) String() string {
func (c Config) String() string {
return marshal(c).String()
}
func (c Config) MarshalText() ([]byte, error) {
return marshal(c).Bytes(), nil
}
func marshal(c Config) *bytes.Buffer {
var buf bytes.Buffer
for i := range c.Hosts {
buf.WriteString(c.Hosts[i].String())
}
return buf.String()
return &buf
}
// Pattern is a pattern in a Host declaration. Patterns are read-only values;