Skip to content

Commit

Permalink
linter
Browse files Browse the repository at this point in the history
  • Loading branch information
donseba committed Nov 19, 2024
1 parent 655b6d6 commit f366d18
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 12 deletions.
52 changes: 42 additions & 10 deletions partial.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,22 +267,54 @@ func (p *Partial) Clone() *Partial {
p.mu.RLock()
defer p.mu.RUnlock()

clone := *p
clone.mu = sync.RWMutex{}
clone.children = make(map[string]*Partial)
for k, v := range p.children {
clone.children[k] = v
// Create a new Partial instance
clone := &Partial{
id: p.id,
parent: p.parent,
swapOOB: p.swapOOB,
fs: p.fs,
logger: p.logger,
partialHeader: p.partialHeader,
requestHeader: p.requestHeader,
useCache: p.useCache,
templates: append([]string{}, p.templates...), // Copy the slice
combinedFunctions: make(template.FuncMap),
data: make(map[string]any),
layoutData: make(map[string]any),
globalData: make(map[string]any),
children: make(map[string]*Partial),
oobChildren: make(map[string]struct{}),
// Do not copy the mutex (mu)
}

// Copy the maps
for k, v := range p.combinedFunctions {
clone.combinedFunctions[k] = v
}
clone.data = make(map[string]any)

for k, v := range p.data {
clone.data[k] = v
}
clone.combinedFunctions = make(template.FuncMap)
for k, v := range p.combinedFunctions {
clone.combinedFunctions[k] = v

for k, v := range p.layoutData {
clone.layoutData[k] = v
}

for k, v := range p.globalData {
clone.globalData[k] = v
}

// Copy the children map
for k, v := range p.children {
clone.children[k] = v
}

// Copy the out-of-band children set
for k, v := range p.oobChildren {
clone.oobChildren[k] = v
}

return &clone
return clone
}

func (p *Partial) getFuncs(data *Data) template.FuncMap {
Expand Down
3 changes: 1 addition & 2 deletions service.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ type (
FuncMap template.FuncMap
Logger Logger
fs fs.FS
funcMapLock sync.RWMutex // Add a read-write mutex
}

Service struct {
Expand Down Expand Up @@ -212,7 +211,7 @@ func (l *Layout) applyConfigToPartial(p *Partial) {
}

// Combine functions only once
combinedFunctions := l.combinedFunctions
combinedFunctions := l.getFuncMap()

p.mergeFuncMapInternal(combinedFunctions)

Expand Down

0 comments on commit f366d18

Please sign in to comment.