diff --git a/gorazor/layout.go b/gorazor/layout.go index daa5a70..449b909 100644 --- a/gorazor/layout.go +++ b/gorazor/layout.go @@ -2,23 +2,22 @@ package gorazor import "sync" -// LayoutManager is the layout manager -type LayoutManager struct { +type layoutManager struct { // For gorazor just process on single one gohtml file now // we use an singleton map to keep layout relationship // Not a good solution but works layoutMap map[string][]string } -var single *LayoutManager +var single *layoutManager var mutexLock sync.RWMutex // LayoutArgs returns arguments of given layout file func LayoutArgs(file string) []string { mutexLock.RLock() defer mutexLock.RUnlock() - manager := newManager() - if args, ok := manager.layoutMap[file]; ok { + + if args, ok := single.layoutMap[file]; ok { return args } return []string{} @@ -27,17 +26,12 @@ func LayoutArgs(file string) []string { // SetLayout arguments for layout file func SetLayout(file string, args []string) { mutexLock.Lock() - manager := newManager() - manager.layoutMap[file] = args - mutexLock.Unlock() + defer mutexLock.Unlock() + + single.layoutMap[file] = args } -func newManager() *LayoutManager { - if single != nil { - return single - } - lay := &LayoutManager{} - lay.layoutMap = map[string][]string{} - single = lay - return lay +func init() { + single = &layoutManager{} + single.layoutMap = map[string][]string{} }