Skip to content

Commit f366d18

Browse files
committed
linter
1 parent 655b6d6 commit f366d18

File tree

2 files changed

+43
-12
lines changed

2 files changed

+43
-12
lines changed

partial.go

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -267,22 +267,54 @@ func (p *Partial) Clone() *Partial {
267267
p.mu.RLock()
268268
defer p.mu.RUnlock()
269269

270-
clone := *p
271-
clone.mu = sync.RWMutex{}
272-
clone.children = make(map[string]*Partial)
273-
for k, v := range p.children {
274-
clone.children[k] = v
270+
// Create a new Partial instance
271+
clone := &Partial{
272+
id: p.id,
273+
parent: p.parent,
274+
swapOOB: p.swapOOB,
275+
fs: p.fs,
276+
logger: p.logger,
277+
partialHeader: p.partialHeader,
278+
requestHeader: p.requestHeader,
279+
useCache: p.useCache,
280+
templates: append([]string{}, p.templates...), // Copy the slice
281+
combinedFunctions: make(template.FuncMap),
282+
data: make(map[string]any),
283+
layoutData: make(map[string]any),
284+
globalData: make(map[string]any),
285+
children: make(map[string]*Partial),
286+
oobChildren: make(map[string]struct{}),
287+
// Do not copy the mutex (mu)
288+
}
289+
290+
// Copy the maps
291+
for k, v := range p.combinedFunctions {
292+
clone.combinedFunctions[k] = v
275293
}
276-
clone.data = make(map[string]any)
294+
277295
for k, v := range p.data {
278296
clone.data[k] = v
279297
}
280-
clone.combinedFunctions = make(template.FuncMap)
281-
for k, v := range p.combinedFunctions {
282-
clone.combinedFunctions[k] = v
298+
299+
for k, v := range p.layoutData {
300+
clone.layoutData[k] = v
301+
}
302+
303+
for k, v := range p.globalData {
304+
clone.globalData[k] = v
305+
}
306+
307+
// Copy the children map
308+
for k, v := range p.children {
309+
clone.children[k] = v
310+
}
311+
312+
// Copy the out-of-band children set
313+
for k, v := range p.oobChildren {
314+
clone.oobChildren[k] = v
283315
}
284316

285-
return &clone
317+
return clone
286318
}
287319

288320
func (p *Partial) getFuncs(data *Data) template.FuncMap {

service.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ type (
3131
FuncMap template.FuncMap
3232
Logger Logger
3333
fs fs.FS
34-
funcMapLock sync.RWMutex // Add a read-write mutex
3534
}
3635

3736
Service struct {
@@ -212,7 +211,7 @@ func (l *Layout) applyConfigToPartial(p *Partial) {
212211
}
213212

214213
// Combine functions only once
215-
combinedFunctions := l.combinedFunctions
214+
combinedFunctions := l.getFuncMap()
216215

217216
p.mergeFuncMapInternal(combinedFunctions)
218217

0 commit comments

Comments
 (0)