add template path from config file
This commit is contained in:
parent
e909aea534
commit
0ce5d76e07
2
boot.go
2
boot.go
|
@ -16,7 +16,7 @@ func boot_system() (*lib.Environment, error) {
|
|||
if err != nil {
|
||||
return env, err
|
||||
}
|
||||
env.Template, err = lib.LoadTemplates(`templates`)
|
||||
env.Template, err = lib.LoadTemplates(settings.Templates)
|
||||
if err != nil {
|
||||
return env, err
|
||||
}
|
||||
|
|
|
@ -3,3 +3,6 @@
|
|||
# more information can be obtained on the github page of the driver
|
||||
# http://godoc.org/github.com/lib/pq
|
||||
connection: user=zeroblog password=foobar sslmode=disable
|
||||
|
||||
# the base template directory
|
||||
templates: templates
|
||||
|
|
|
@ -8,6 +8,7 @@ import (
|
|||
|
||||
type Settings struct {
|
||||
Connection string
|
||||
Templates string
|
||||
}
|
||||
|
||||
type Environment struct {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package lib
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"log"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
|
@ -15,6 +16,8 @@ type fileList struct {
|
|||
|
||||
// load all templates found as childs of the path
|
||||
func LoadTemplates(path string) (*template.Template, error) {
|
||||
// TODO add better check for template directory
|
||||
if path == "" { return nil, errors.New("template path empty") }
|
||||
f := &fileList{len(path), &template.Template{}}
|
||||
|
||||
err := filepath.Walk(path, f.scanFile)
|
||||
|
|
Loading…
Reference in New Issue