2017-04-04 11:10:35 +00:00
|
|
|
package generator
|
|
|
|
|
|
|
|
import (
|
|
|
|
"go/format"
|
|
|
|
"io/ioutil"
|
|
|
|
)
|
|
|
|
|
2017-06-13 11:56:07 +00:00
|
|
|
// File is the function's type that generate source file from a file to be parsed, linguist's samples dir and a template.
|
|
|
|
type File func(fileToParse, samplesDir, outPath, tmplPath, tmplName, commit string) error
|
2017-05-25 10:33:26 +00:00
|
|
|
|
|
|
|
func formatedWrite(outPath string, source []byte) error {
|
2017-04-04 11:10:35 +00:00
|
|
|
formatedSource, err := format.Source(source)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := ioutil.WriteFile(outPath, formatedSource, 0666); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|