github.com/theliebeskind/genfig@v0.1.5-alpha/writers/initer.go (about)

     1  package writers
     2  
     3  import (
     4  	"io"
     5  	"text/template"
     6  )
     7  
     8  var (
     9  	initTpl = template.Must(template.New("init").Parse(`import (
    10  	"os"
    11  	"fmt"
    12  )
    13  
    14  var (
    15  	_ = os.Getenv
    16  	_ = fmt.Printf
    17  )
    18  
    19  // Current is the current config, selected by the curren env and
    20  // updated by the availalbe env vars
    21  var Current *Config
    22  
    23  // This init tries to retrieve the current environment via the
    24  // common env var 'ENV' and applies activated plugins
    25  func init() {
    26  	Current, _ = Get(os.Getenv("ENV"))
    27  	{{range $k, $v := .PluginCalls}}
    28  	// calling plugin {{$k}}
    29  	{{$v}}
    30  	{{end}}
    31  }
    32  	
    33  `))
    34  )
    35  
    36  //WriteInit writes
    37  func WriteInit(w io.Writer, pluginCalls map[string]string) error {
    38  	return initTpl.Execute(w, struct {
    39  		PluginCalls map[string]string
    40  	}{PluginCalls: pluginCalls})
    41  }