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 package moq
import ( import (
"bytes"
"errors" "errors"
"fmt" "fmt"
"go/ast" "go/ast"
"go/format"
"go/parser" "go/parser"
"go/token" "go/token"
"go/types" "go/types"
@ -109,10 +111,18 @@ func (m *Mocker) Mock(w io.Writer, name ...string) error {
for pkgToImport := range m.imports { for pkgToImport := range m.imports {
doc.Imports = append(doc.Imports, pkgToImport) 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 { if err != nil {
return err 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 return nil
} }