// saveAsGoBinData creates a `schema.go` source file for each parsed service. // Output file contains a compressed data representation of parsed schemas // and `_bindata` map which keys represent json methods' name. func (s *schg) saveAsGoBinData(schemaOutBase string) (err error) { ch, ret := make(chan *bindata.Config, len(s.services)), make(chan error) for serv, path := range s.services { subdir := serv if s.merge || serv == filepath.Base(schemaOutBase) { subdir = "" } ch <- &bindata.Config{ Package: serv, Input: []bindata.InputConfig{bindata.InputConfig{Path: path}}, Output: filepath.Join(schemaOutBase, subdir, "schema.go"), Prefix: path, Recursive: true, Fmt: true, } } defer close(ch) for n := min(runtime.GOMAXPROCS(-1), len(s.services)); n > 0; n-- { go func() { for c := range ch { ret <- bindata.Generate(c) } }() } var e error for _ = range s.services { if err := <-ret; err != nil { e = err } } return e }
func main() { c, auto := parseArgs() if auto { cfgs, err := bindata.Glob(os.Getenv("GOPATH")) if err != nil { die(err) } for _, cfg := range cfgs { copycfg(cfg, c) } if !bindata.GlobGenerate(cfgs, log) { os.Exit(1) } return } if err := bindata.Generate(c); err != nil { die(err) } }