go-bindata static files and templates
This commit is contained in:
parent
79e5ec435a
commit
4a83136970
6 changed files with 32 additions and 9 deletions
|
@ -123,7 +123,11 @@ func (provider *DockerProvider) loadDockerConfig() *Configuration {
|
|||
provider.Domain,
|
||||
}
|
||||
gtf.Inject(DockerFuncMap)
|
||||
tmpl, err := template.New(provider.Filename).Funcs(DockerFuncMap).ParseFiles(provider.Filename)
|
||||
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
|
||||
|
|
10
generate.go
Normal file
10
generate.go
Normal file
|
@ -0,0 +1,10 @@
|
|||
/*
|
||||
Copyright
|
||||
*/
|
||||
|
||||
//go:generate go get github.com/jteeuwen/go-bindata/...
|
||||
//go:generate go get github.com/elazarl/go-bindata-assetfs/...
|
||||
//go:generate rm -vf gen.go
|
||||
//go:generate go-bindata -o gen.go static/... templates/... providerTemplates/...
|
||||
|
||||
package main
|
|
@ -138,7 +138,11 @@ func (provider *MarathonProvider) loadMarathonConfig() *Configuration {
|
|||
}
|
||||
|
||||
gtf.Inject(MarathonFuncMap)
|
||||
tmpl, err := template.New(provider.Filename).Funcs(MarathonFuncMap).ParseFiles(provider.Filename)
|
||||
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
|
||||
|
|
9
web.go
9
web.go
|
@ -7,9 +7,14 @@ import (
|
|||
"fmt"
|
||||
"io/ioutil"
|
||||
"encoding/json"
|
||||
"github.com/elazarl/go-bindata-assetfs"
|
||||
)
|
||||
|
||||
var renderer = render.New()
|
||||
var renderer = render.New(render.Options{
|
||||
Directory: "templates",
|
||||
Asset: Asset,
|
||||
AssetNames: AssetNames,
|
||||
})
|
||||
|
||||
type WebProvider struct {
|
||||
Address string
|
||||
|
@ -36,7 +41,7 @@ func (provider *WebProvider) Provide(configurationChan chan<- *Configuration){
|
|||
http.Error(rw, fmt.Sprintf("%+v", err), http.StatusBadRequest)
|
||||
}
|
||||
}))
|
||||
systemRouter.PathPrefix("/static/").Handler(http.StripPrefix("/static/", http.FileServer(http.Dir("static/"))))
|
||||
systemRouter.PathPrefix("/static").Handler(http.StripPrefix("/static/", http.FileServer(&assetfs.AssetFS{Asset: Asset, AssetDir: AssetDir, Prefix: "static"})))
|
||||
|
||||
go http.ListenAndServe(provider.Address, systemRouter)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue