github.com/theliebeskind/genfig@v0.1.5-alpha/writers/plugins.go (about) 1 package writers 2 3 import ( 4 "os" 5 "path/filepath" 6 7 "github.com/theliebeskind/genfig/plugins" 8 9 "github.com/theliebeskind/genfig/models" 10 ) 11 12 const ( 13 pluginPrefix = "plugin_" 14 ) 15 16 //WritePlugins writes a plugin file for each plugin 17 func WritePlugins(schema models.SchemaMap, dir string, pkg string, cmd string, calls map[string]string) ([]string, error) { 18 files := []string{} 19 for n, p := range plugins.Plugins { 20 p.SetSchemaMap(schema) 21 path := filepath.Join(dir, pluginPrefix+n+".go") 22 if f, err := os.Create(path); err != nil { 23 return files, err 24 } else if err := WriteHeader(f, pkg, cmd+" plugin '"+n+"'"); err != nil { 25 return files, err 26 } else if _, err := p.WriteTo(f); err != nil { 27 return files, err 28 } else { 29 _ = f.Close() 30 files = append(files, path) 31 } 32 if c, has := p.GetInitCall(); has { 33 calls[n] = c 34 } 35 } 36 return files, nil 37 }