Commits

Miki Tebeka committed 32dc39d

Call initialize in LoadTemplates as well

Comments (0)

Files changed (1)

 	"os"
 	"path/filepath"
 	"strings"
+	"sync"
 	"time"
 )
 
 )
 
 var ResourceMap map[string]Resource = nil
+var initMutex sync.Mutex
 
 func loadMap() (map[string]Resource, error) {
 	this := os.Args[0]
 }
 
 func Initialize() error {
+	initMutex.Lock()
+	defer initMutex.Unlock()
+
 	if ResourceMap != nil {
 		return nil
 	}
 type handler int
 
 func (h handler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
-	rsc := ResourceMap[req.URL.Path]
+	rsc := Get(req.URL.Path)
 	if rsc == nil {
 		http.NotFound(w, req)
 		return
 
 // Handle register HTTP handler under prefix
 func Handle(prefix string) error {
-	Initialize()
+	if err := Initialize(); err != nil {
+		return err
+	}
+
 	if !strings.HasSuffix(prefix, "/") {
 		prefix += "/"
 	}
 // LoadTemplates loads named templates from resources.
 // If the argument "t" is nil, it is created from the first resource.
 func LoadTemplates(t *template.Template, filenames ...string) (*template.Template, error) {
+	if err := Initialize(); err != nil {
+		return nil, err
+	}
+
 	if len(filenames) == 0 {
 		// Not really a problem, but be consistent.
 		return nil, fmt.Errorf("no files named in call to LoadTemplates")