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, provider.Domain,
} }
gtf.Inject(DockerFuncMap) gtf.Inject(DockerFuncMap)
buf, err := Asset("providerTemplates/docker.tmpl") tmpl := template.New(provider.Filename).Funcs(DockerFuncMap)
if err != nil { if(len(provider.Filename) > 0){
log.Error("Error reading file", err) _, err := tmpl.ParseFiles(provider.Filename)
}
tmpl, err := template.New(provider.Filename).Funcs(DockerFuncMap).Parse(string(buf))
if err != nil { if err != nil {
log.Error("Error reading file", err) log.Error("Error reading file", err)
return nil 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 var buffer bytes.Buffer
err := tmpl.Execute(&buffer, templateObjects)
err = tmpl.Execute(&buffer, templateObjects)
if err != nil { if err != nil {
log.Error("Error with docker template", err) log.Error("Error with docker template", err)
return nil return nil

View file

@ -138,15 +138,24 @@ func (provider *MarathonProvider) loadMarathonConfig() *Configuration {
} }
gtf.Inject(MarathonFuncMap) gtf.Inject(MarathonFuncMap)
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") buf, err := Asset("providerTemplates/marathon.tmpl")
if err != nil { if err != nil {
log.Error("Error reading file", err) log.Error("Error reading file", err)
} }
tmpl, err := template.New(provider.Filename).Funcs(MarathonFuncMap).ParseFiles(string(buf)) _, err = tmpl.Parse(string(buf))
if err != nil { if err != nil {
log.Error("Error reading file:", err) log.Error("Error reading file", err)
return nil return nil
} }
}
var buffer bytes.Buffer var buffer bytes.Buffer

View file

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

View file

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