github.com/rohankumardubey/go-enry@v1.7.3/internal/code-generator/generator/vendor.go (about) 1 package generator 2 3 import ( 4 "bytes" 5 "io" 6 "io/ioutil" 7 8 "gopkg.in/yaml.v2" 9 ) 10 11 // Vendor generates regex matchers in Go for vendoring files/dirs. 12 // It is of generator.File type. 13 func Vendor(fileToParse, samplesDir, outPath, tmplPath, tmplName, commit string) error { 14 data, err := ioutil.ReadFile(fileToParse) 15 if err != nil { 16 return err 17 } 18 19 var regexpList []string 20 if err := yaml.Unmarshal(data, ®expList); err != nil { 21 return nil 22 } 23 24 buf := &bytes.Buffer{} 25 if err := executeVendorTemplate(buf, regexpList, tmplPath, tmplName, commit); err != nil { 26 return nil 27 } 28 29 return formatedWrite(outPath, buf.Bytes()) 30 } 31 32 func executeVendorTemplate(out io.Writer, regexpList []string, tmplPath, tmplName, commit string) error { 33 return executeTemplate(out, tmplName, tmplPath, commit, nil, regexpList) 34 }