Files
lenz-web/xmlmodels/public.go
Simon Martens 052f21e87a Index functions
2025-03-26 16:18:53 +01:00

41 lines
629 B
Go

package xmlmodels
import (
"sync"
xmlparsing "github.com/Theodor-Springmann-Stiftung/lenz-web/xml"
)
var lib *Library
var mu sync.RWMutex
func Set(l *Library) {
mu.Lock()
defer mu.Unlock()
if lib != nil {
panic("Trying to reinitialize Library")
}
lib = l
}
func Get() *Library {
mu.RLock()
defer mu.RUnlock()
if lib == nil {
panic("Trying to get uninitialized Library")
}
return lib
}
func Parse(dir, hash string) (*Library, error) {
if lib == nil {
Set(NewLibrary())
}
if hash == "" {
return Get(), lib.Parse(xmlparsing.Path, dir, hash)
}
return Get(), lib.Parse(xmlparsing.Commit, dir, hash)
}