Skip to content

Commit

Permalink
Simplified layout manager
Browse files Browse the repository at this point in the history
  • Loading branch information
Wuvist committed May 28, 2019
1 parent 8a54986 commit 36ea11c
Showing 1 changed file with 10 additions and 16 deletions.
26 changes: 10 additions & 16 deletions gorazor/layout.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand All @@ -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{}
}

0 comments on commit 36ea11c

Please sign in to comment.