added go fmt

This commit is contained in:
Mat Ryer 2017-07-31 15:09:54 +01:00
parent 9999c4d497
commit fc157a141f

View File

@ -1,9 +1,11 @@
package moq
import (
"bytes"
"errors"
"fmt"
"go/ast"
"go/format"
"go/parser"
"go/token"
"go/types"
@ -109,10 +111,18 @@ func (m *Mocker) Mock(w io.Writer, name ...string) error {
for pkgToImport := range m.imports {
doc.Imports = append(doc.Imports, pkgToImport)
}
err := m.tmpl.Execute(w, doc)
var buf bytes.Buffer
err := m.tmpl.Execute(&buf, doc)
if err != nil {
return err
}
formatted, err := format.Source(buf.Bytes())
if err != nil {
return fmt.Errorf("go/format: %s", err)
}
if _, err := w.Write(formatted); err != nil {
return err
}
return nil
}