go-bindata static files and templates

This commit is contained in:
emile 2015-09-11 19:25:49 +02:00
parent 7d4675f542
commit 95557a8dba
4 changed files with 41 additions and 24 deletions

View file

@ -123,19 +123,27 @@ func (provider *DockerProvider) loadDockerConfig() *Configuration {
provider.Domain,
}
gtf.Inject(DockerFuncMap)
buf, err := Asset("providerTemplates/docker.tmpl")
if err != nil {
log.Error("Error reading file", err)
}
tmpl, err := template.New(provider.Filename).Funcs(DockerFuncMap).Parse(string(buf))
if err != nil {
log.Error("Error reading file", err)
return nil
tmpl := template.New(provider.Filename).Funcs(DockerFuncMap)
if(len(provider.Filename) > 0){
_, err := tmpl.ParseFiles(provider.Filename)
if err != nil {
log.Error("Error reading file", err)
return nil
}
}else{
buf, err := Asset("providerTemplates/docker.tmpl")
if err != nil {
log.Error("Error reading file", err)
}
_, err = tmpl.Parse(string(buf))
if err != nil {
log.Error("Error reading file", err)
return nil
}
}
var buffer bytes.Buffer
err = tmpl.Execute(&buffer, templateObjects)
err := tmpl.Execute(&buffer, templateObjects)
if err != nil {
log.Error("Error with docker template", err)
return nil

View file

@ -138,14 +138,23 @@ func (provider *MarathonProvider) loadMarathonConfig() *Configuration {
}
gtf.Inject(MarathonFuncMap)
buf, err := Asset("providerTemplates/marathon.tmpl")
if err != nil {
log.Error("Error reading file", err)
}
tmpl, err := template.New(provider.Filename).Funcs(MarathonFuncMap).ParseFiles(string(buf))
if err != nil {
log.Error("Error reading file:", err)
return nil
tmpl := template.New(provider.Filename).Funcs(DockerFuncMap)
if(len(provider.Filename) > 0){
_, err := tmpl.ParseFiles(provider.Filename)
if err != nil {
log.Error("Error reading file", err)
return nil
}
}else{
buf, err := Asset("providerTemplates/marathon.tmpl")
if err != nil {
log.Error("Error reading file", err)
}
_, err = tmpl.Parse(string(buf))
if err != nil {
log.Error("Error reading file", err)
return nil
}
}
var buffer bytes.Buffer

View file

@ -201,13 +201,13 @@ func LoadConfig(configuration *Configuration, gloablConfiguration *GlobalConfigu
}
backends[route.Backend]=lb
}else {
log.Debug("Reusing backend", route.Backend)
log.Debug("Reusing backend %s", route.Backend)
}
for _, muxRoute := range newRoutes {
if (len(gloablConfiguration.AccessLogsFile) > 0 ) {
fi, err := os.OpenFile(gloablConfiguration.AccessLogsFile, os.O_RDWR | os.O_CREATE | os.O_APPEND, 0666)
if err != nil {
log.Fatal("Error opening file", err)
log.Fatal("Error opening file ", err)
}
muxRoute.Handler(handlers.CombinedLoggingHandler(fi, backends[route.Backend]))
}else {
@ -215,7 +215,7 @@ func LoadConfig(configuration *Configuration, gloablConfiguration *GlobalConfigu
}
err := muxRoute.GetError()
if err != nil {
log.Error("Error building route", err)
log.Error("Error building route ", err)
}
}
}
@ -233,7 +233,7 @@ func Invoke(any interface{}, name string, args ...interface{}) []reflect.Value {
func LoadFileConfig(file string) *GlobalConfiguration {
configuration := NewGlobalConfiguration()
if _, err := toml.DecodeFile(file, configuration); err != nil {
log.Fatal("Error reading file", err)
log.Fatal("Error reading file ", err)
}
log.Debug("Global configuration loaded %+v", configuration)
return configuration

View file

@ -9,8 +9,8 @@ logLevel = "DEBUG"
endpoint = "unix:///var/run/docker.sock"
watch = true
domain = "toto.fr"
filename = "docker.tmpl"
#
# filename = "docker.tmpl"
# [marathon]
# endpoint = "http://127.0.0.1:8080"
# networkInterface = "eth0"