accounts/abi/bind: pass Go code through gofmt again

goimports used to do this formatting. To keep the generated code
in gofmt style, we now need to format it here ourselves.
This commit is contained in:
Jeremy Schlatter 2018-09-28 13:29:06 -07:00
parent d260c5f5e1
commit 378d865e84

View file

@ -23,6 +23,7 @@ package bind
import ( import (
"bytes" "bytes"
"fmt" "fmt"
"go/format"
"regexp" "regexp"
"strings" "strings"
"text/template" "text/template"
@ -144,7 +145,15 @@ func Bind(types []string, abis []string, bytecodes []string, pkg string, lang La
if err := tmpl.Execute(buffer, data); err != nil { if err := tmpl.Execute(buffer, data); err != nil {
return "", err return "", err
} }
// For Go bindings pass the code through gofmt to clean it up
if lang == LangGo {
code, err := format.Source(buffer.Bytes())
if err != nil {
return "", fmt.Errorf("%v\n%s", err, buffer)
}
return string(code), nil
}
// For all others just return as is for now
return buffer.String(), nil return buffer.String(), nil
} }